{"_id":"@dharayush7/fireclass-js","_rev":"2-5855d60b486c48a67da3146896436571","name":"@dharayush7/fireclass-js","dist-tags":{"latest":"2.0.9"},"versions":{"2.0.8":{"name":"@dharayush7/fireclass-js","version":"2.0.8","keywords":["firestore","firebase","firebase-admin","orm","model","typescript","type-safe","validation","class-validator","express","nodejs","server-side","query-builder","fireclass"],"author":{"url":"https://www.ayushdhar.com","name":"Ayush Dhar","email":"contact@ayushdhar.com"},"license":"MIT","_id":"@dharayush7/fireclass-js@2.0.8","maintainers":[{"name":"dharayush7","email":"dharayush7@gmail.com"}],"homepage":"https://fireclass.ayushdhar.com","bugs":{"url":"https://github.com/dharayush7/fireclass-js/issues"},"dist":{"shasum":"466e7da9d08890a0f349622c973ad5d152009339","tarball":"https://registry.npmjs.org/@dharayush7/fireclass-js/-/fireclass-js-2.0.8.tgz","fileCount":9,"integrity":"sha512-ZrVITvvuxjKkVcPcmG3xnby+QjyvC0cHDjAa2p/zWMJA11RbS2wA1MicyFKyTXbILdj2LyZ8VTxhIBYlGjn1Uw==","signatures":[{"sig":"MEUCIESGunEwiHdUbQYHviAF/JjIJruwbpQUow/qDkvY2c2xAiEA04MsXolNtlpnvjHi13Nh47NZKe8ab9h/uYuBCFcBGi8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":44202},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"46586f635f0b35afd8691537344520225bc260aa","scripts":{"test":"vitest run","build":"tsup","typecheck":"tsc --noEmit","test:watch":"vitest","prepublishOnly":"npm run typecheck && npm run test && npm run build"},"_npmUser":{"name":"dharayush7","email":"dharayush7@gmail.com"},"repository":{"url":"git+https://github.com/dharayush7/fireclass-js.git","type":"git"},"_npmVersion":"11.12.1","description":"Type-safe Firestore models for Node.js and Express, powered by firebase-admin. The firebase-admin runtime of the Fireclass suite.","directories":{},"sideEffects":false,"_nodeVersion":"24.15.0","dependencies":{"@dharayush7/fireclass-core":"^2.0.8"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.1","vitest":"^2.1.9","typescript":"^5.9.3","@types/node":"^24.13.3","firebase-admin":"^13.6.0","class-validator":"^0.14.3","reflect-metadata":"^0.2.2","class-transformer":"^0.5.1"},"peerDependencies":{"firebase-admin":"^12.0.0 || ^13.0.0","class-validator":"^0.14.0","class-transformer":"^0.5.0"},"_npmOperationalInternal":{"tmp":"tmp/fireclass-js_2.0.8_1783599308975_0.5642158276138478","host":"s3://npm-registry-packages-npm-production"}},"2.0.9":{"name":"@dharayush7/fireclass-js","version":"2.0.9","description":"Type-safe Firestore ODM for Node.js and Express using Firebase Admin, with validated models, typed CRUD and queries, and error middleware.","license":"MIT","author":{"name":"Ayush Dhar","email":"contact@ayushdhar.com","url":"https://www.ayushdhar.com"},"repository":{"type":"git","url":"git+https://github.com/dharayush7/fireclass-js.git"},"homepage":"https://fireclass.ayushdhar.com/docs/api/js","bugs":{"url":"https://github.com/dharayush7/fireclass-js/issues"},"keywords":["fireclass","firestore","firebase","firebase-admin","firestore-orm","firebase-orm","typescript-orm","odm","object-document-mapper","firestore-model","typed-firestore","firestore-typescript","orm","model","data-modeling","crud","database","nosql","typescript","type-safe","validation","class-validator","class-transformer","express","node","nodejs","server-side","backend","cloud-functions","serverless","query-builder","error-middleware"],"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"sideEffects":false,"scripts":{"build":"tsup","test":"vitest run","test:watch":"vitest","typecheck":"tsc --noEmit","prepublishOnly":"npm run typecheck && npm run test && npm run build"},"peerDependencies":{"class-transformer":"^0.5.0","class-validator":"^0.14.0","firebase-admin":"^12.0.0 || ^13.0.0"},"devDependencies":{"@types/node":"^24.13.3","class-transformer":"^0.5.1","class-validator":"^0.14.3","firebase-admin":"^13.6.0","reflect-metadata":"^0.2.2","tsup":"^8.5.1","typescript":"^5.9.3","vitest":"^2.1.9"},"publishConfig":{"access":"public"},"dependencies":{"@dharayush7/fireclass-core":"^2.0.8"},"gitHead":"1b70df2f3f1d780c2c1a52c01f19a93c12532c29","_id":"@dharayush7/fireclass-js@2.0.9","_nodeVersion":"24.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-7GuPmEP/uvOP+dqWRR8FEiXSNdJb8S6ORzCu180Zfy/2wMD3wYOZ1nax/yEXwUxPYR3IieANoe9esiP/Jy3/HA==","shasum":"ee86e3548c4375b62af3d5b1e913555dfeea5ea8","tarball":"https://registry.npmjs.org/@dharayush7/fireclass-js/-/fireclass-js-2.0.9.tgz","fileCount":11,"unpackedSize":52716,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCE3Nc/KqeQ6hn57/t55TBcamtdFdeVtc3yq7LaoAAvWwIgS5/JDp3FYLDwh1VndkEg0QExYLG1IjgKlcZ5cGNs2qo="}]},"_npmUser":{"name":"dharayush7","email":"dharayush7@gmail.com"},"directories":{},"maintainers":[{"name":"dharayush7","email":"dharayush7@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/fireclass-js_2.0.9_1783699781407_0.6199608778489687"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-09T12:15:08.652Z","modified":"2026-07-10T16:09:41.821Z","2.0.8":"2026-07-09T12:15:09.113Z","2.0.9":"2026-07-10T16:09:41.534Z"},"bugs":{"url":"https://github.com/dharayush7/fireclass-js/issues"},"author":{"name":"Ayush Dhar","email":"contact@ayushdhar.com","url":"https://www.ayushdhar.com"},"license":"MIT","homepage":"https://fireclass.ayushdhar.com/docs/api/js","keywords":["fireclass","firestore","firebase","firebase-admin","firestore-orm","firebase-orm","typescript-orm","odm","object-document-mapper","firestore-model","typed-firestore","firestore-typescript","orm","model","data-modeling","crud","database","nosql","typescript","type-safe","validation","class-validator","class-transformer","express","node","nodejs","server-side","backend","cloud-functions","serverless","query-builder","error-middleware"],"repository":{"type":"git","url":"git+https://github.com/dharayush7/fireclass-js.git"},"description":"Type-safe Firestore ODM for Node.js and Express using Firebase Admin, with validated models, typed CRUD and queries, and error middleware.","maintainers":[{"name":"dharayush7","email":"dharayush7@gmail.com"}],"readme":"<p align=\"center\">\n  <a href=\"https://fireclass.ayushdhar.com\">\n    <img src=\"https://fireclass.ayushdhar.com/logo.png\" alt=\"Fireclass logo\" width=\"120\" height=\"120\" />\n  </a>\n</p>\n\n<h1 align=\"center\">@dharayush7/fireclass-js</h1>\n\n<p align=\"center\">\n  Type-safe Firestore models, validated CRUD, typed queries, and Express error handling for Node.js with Firebase Admin.\n</p>\n\n<p align=\"center\">\n  <a href=\"https://fireclass.ayushdhar.com/docs/installation/express\">Setup</a> |\n  <a href=\"https://fireclass.ayushdhar.com/docs/api/js\">API reference</a> |\n  <a href=\"https://fireclass.ayushdhar.com/docs/guides/express\">Express guide</a> |\n  <a href=\"https://github.com/dharayush7/fireclass-js\">GitHub</a> |\n  <a href=\"https://www.npmjs.com/package/@dharayush7/fireclass-js\">npm</a>\n</p>\n\n<code>@dharayush7/fireclass-js</code> binds the shared Fireclass model API to\n<code>firebase-admin/firestore</code>. Use it in Node.js servers, Express\napplications, workers, Cloud Functions, and other trusted server runtimes.\n\n> **Server-only package:** Firebase Admin bypasses client Firestore Security\n> Rules. Never import this package into browser code or expose service-account\n> values to clients.\n\n## Prerequisites\n\n- Node.js application with TypeScript decorators enabled.\n- Firebase project with Firestore enabled.\n- Application Default Credentials or Firebase Admin service-account values.\n- A gitignored environment file or managed secret store for private keys.\n\n## Installation\n\n~~~bash\nnpm install @dharayush7/fireclass-js firebase-admin class-validator class-transformer reflect-metadata\n~~~\n\nEnable decorators:\n\n~~~jsonc\n{\n  \"compilerOptions\": {\n    \"module\": \"NodeNext\",\n    \"moduleResolution\": \"NodeNext\",\n    \"experimentalDecorators\": true,\n    \"emitDecoratorMetadata\": true\n  }\n}\n~~~\n\n## Firebase Admin setup\n\nStore credentials outside source control:\n\n~~~bash\nPROJECT_ID=your-project-id\nCLIENT_EMAIL=firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com\nPRIVATE_KEY=\"-----BEGIN PRIVATE KEY-----\\n...\\n-----END PRIVATE KEY-----\\n\"\n~~~\n\nCreate a memoized Firebase entry:\n\n~~~ts\n// src/lib/firebase.ts\nimport \"dotenv/config\";\nimport { cert, getApps, initializeApp } from \"firebase-admin/app\";\nimport { getFirestore, type Firestore } from \"firebase-admin/firestore\";\n\nexport function getDb(): Firestore {\n  if (getApps().length === 0) {\n    initializeApp({\n      credential: cert({\n        projectId: process.env.PROJECT_ID,\n        clientEmail: process.env.CLIENT_EMAIL,\n        privateKey: process.env.PRIVATE_KEY?.replace(/\\\\n/g, \"\\n\"),\n      }),\n    });\n  }\n\n  return getFirestore();\n}\n~~~\n\nCreate the application binding:\n\n~~~ts\n// src/lib/fireclass.ts\nimport \"reflect-metadata\";\nimport { createFireclass } from \"@dharayush7/fireclass-js\";\nimport { getDb } from \"./firebase.js\";\n\nexport const { BaseModel, adapter } = createFireclass(getDb());\n~~~\n\nThe local Fireclass file should export initialized values only. Import\ndecorators, query types, errors, and middleware directly from this package where\nthey are used.\n\n## Define a model\n\n~~~ts\n// src/models/user.ts\nimport { Collection } from \"@dharayush7/fireclass-js\";\nimport { IsEmail, IsInt, IsString, Length, Min } from \"class-validator\";\nimport { BaseModel } from \"../lib/fireclass.js\";\n\n@Collection(\"users\")\nexport class User extends BaseModel<User> {\n  @IsString()\n  @Length(2, 80)\n  name!: string;\n\n  @IsEmail()\n  email!: string;\n\n  @IsInt()\n  @Min(0)\n  age!: number;\n\n  constructor(data?: Partial<User>) {\n    super(data);\n    Object.assign(this, data);\n  }\n}\n~~~\n\n## CRUD and typed queries\n\n~~~ts\nconst id = await new User({\n  name: \"Ada Lovelace\",\n  email: \"ada@example.com\",\n  age: 36,\n}).save();\n\nconst user = await User.findById(id);\n\nconst adults = await User.findMany({\n  where: { age: { gte: 18 } },\n  orderBy: { name: \"asc\" },\n  limit: 20,\n});\n\nif (user) {\n  user.age = 37;\n  await user.save();\n  await user.delete();\n}\n~~~\n\nModel instances provide <code>save()</code> and <code>delete()</code>. Model\nclasses provide <code>findById</code>, <code>findMany</code>,\n<code>findOne</code>, <code>count</code>, <code>deleteById</code>, and\n<code>deleteMany</code>.\n\nSupported query operators are <code>equals</code>, <code>gt</code>,\n<code>gte</code>, <code>lt</code>, <code>lte</code>, <code>in</code>,\n<code>notIn</code>, <code>arrayContains</code>, and\n<code>arrayContainsAny</code>, plus ordering, limits, and\n<code>startAfter</code>.\n\n## Export index\n\n| Export | Purpose |\n| --- | --- |\n| <code>createFireclass(db)</code> | Return a bound <code>BaseModel</code> and <code>AdminAdapter</code> |\n| <code>Fireclass</code> | Return type of <code>createFireclass</code> |\n| <code>getBaseModel(db)</code> | Compatibility alias for the deprecated package |\n| <code>AdminAdapter</code> | Firebase Admin implementation of the core adapter |\n| <code>fireclassErrorHandler(options?)</code> | Express-compatible Fireclass error middleware |\n| <code>FireclassErrorHandlerOptions</code> | Middleware status-code options |\n| Core exports | Decorators, query types, validation, conversion, and errors |\n\n### createFireclass\n\n~~~ts\nfunction createFireclass(db: Firestore): {\n  BaseModel: BaseModelClass;\n  adapter: AdminAdapter;\n};\n~~~\n\nCreate one binding and reuse it. Multiple calls create separate adapter and\nbase-class identities even when they reference the same Firestore instance.\n\n### AdminAdapter\n\n| Method | Firebase Admin operation |\n| --- | --- |\n| <code>add</code> | Collection add |\n| <code>set</code> | Document set with merge |\n| <code>get</code> | Document get |\n| <code>query</code> | Query get |\n| <code>delete</code> | Document delete |\n| <code>batchDelete</code> | Write batches of at most 500 deletes |\n| <code>count</code> | Aggregate count |\n| <code>convert</code> | Recursive Timestamp-to-Date conversion |\n\nRealtime subscriptions are intentionally absent; browser realtime support lives\nin <code>@dharayush7/fireclass-react</code>.\n\n## Express error middleware\n\nRegister Fireclass error middleware after routes:\n\n~~~ts\nimport express from \"express\";\nimport { fireclassErrorHandler } from \"@dharayush7/fireclass-js\";\n\nconst app = express();\napp.use(express.json());\n\n// Register application routes first.\n\napp.use(\n  fireclassErrorHandler({\n    validationStatus: 422,\n    fireclassStatus: 400,\n  }),\n);\n~~~\n\nBoth status options default to 400. Validation failures become:\n\n~~~json\n{\n  \"error\": \"ValidationError\",\n  \"message\": \"Validation failed for \\\"User\\\": email (email must be an email)\",\n  \"details\": [\n    {\n      \"property\": \"email\",\n      \"constraints\": {\n        \"isEmail\": \"email must be an email\"\n      }\n    }\n  ]\n}\n~~~\n\nOther Fireclass failures include their concrete error name and message.\nNon-Fireclass errors are passed to <code>next(error)</code> unchanged.\n\n## Migration from the deprecated package\n\n~~~diff\n- import { getBaseModel } from \"@dharayush7/fireclass/core\";\n+ import { getBaseModel } from \"@dharayush7/fireclass-js\";\n~~~\n\n<code>getBaseModel(db)</code> remains available as a migration alias. Prefer\n<code>createFireclass(db)</code> for new code because it also exposes the\nadapter. Replace legacy subpath imports with direct runtime imports:\n\n~~~ts\nimport {\n  Collection,\n  ValidationFailedError,\n  type QueryOptions,\n} from \"@dharayush7/fireclass-js\";\n~~~\n\nSee the complete\n[legacy migration guide](https://fireclass.ayushdhar.com/docs/guides/migration)\nfor changed errors, return values, and query capabilities.\n\n## CLI setup\n\nAfter Firebase initialization exists, the CLI can create\n<code>fireclass.json</code>, the Fireclass binding, models, and decorator\nconfiguration:\n\n~~~bash\nnpx fireclass init\nnpx fireclass doctor\n~~~\n\nFor an Express factory export, configure <code>getDb()</code> so generated code\ncalls the function.\n\n## Documentation and examples\n\n- [Express installation](https://fireclass.ayushdhar.com/docs/installation/express)\n- [Complete Node/Express API](https://fireclass.ayushdhar.com/docs/api/js)\n- [Express CRUD guide](https://fireclass.ayushdhar.com/docs/guides/express)\n- [Core model API](https://fireclass.ayushdhar.com/docs/api/core)\n- [Runnable Express application](https://github.com/dharayush7/fireclass-cli/tree/main/example/fireclass-express-app)\n\nSee [CHANGELOG.md](./CHANGELOG.md) for version history and\n[RELEASE_NOTES.md](./RELEASE_NOTES.md) for the current release summary.\n\n## License\n\nMIT. Copyright Ayush Dhar.\n","readmeFilename":"README.md"}