{"_id":"@dharayush7/fireclass-ssr","_rev":"2-05e53aae237dbad91f5e27262091b59f","name":"@dharayush7/fireclass-ssr","dist-tags":{"latest":"2.0.9"},"versions":{"2.0.8":{"name":"@dharayush7/fireclass-ssr","version":"2.0.8","keywords":["firestore","firebase","firebase-admin","nextjs","next","rsc","server-components","server-actions","ssr","orm","typescript","type-safe","fireclass"],"author":{"url":"https://www.ayushdhar.com","name":"Ayush Dhar","email":"contact@ayushdhar.com"},"license":"MIT","_id":"@dharayush7/fireclass-ssr@2.0.8","maintainers":[{"name":"dharayush7","email":"dharayush7@gmail.com"}],"homepage":"https://fireclass.ayushdhar.com","bugs":{"url":"https://github.com/dharayush7/fireclass-ssr/issues"},"dist":{"shasum":"415aa2122cfda7146b24faa855739ede3e88b34d","tarball":"https://registry.npmjs.org/@dharayush7/fireclass-ssr/-/fireclass-ssr-2.0.8.tgz","fileCount":17,"integrity":"sha512-wqmtaHYW9MKB44wNwl9YH/BXGn3QkuTWalzjfwxbm1pANaxPOx4znl/4zJswhu6wVcK7IpBT/YDoID4ZWdIyeQ==","signatures":[{"sig":"MEYCIQCSMeF8cu4nYdY+chIiMbmNQbhdMfup9TzCJidoGi9m8AIhAJIRdoBCc4fq5ayPGFqWDDLJamXLGhpIxuN1lw7Rdfss","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":55973},"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"},"./client":{"types":"./dist/client.d.ts","import":"./dist/client.js","require":"./dist/client.cjs"}},"gitHead":"83e60f780ff3b9c0509c40eac8a396472e732454","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-ssr.git","type":"git"},"_npmVersion":"11.12.1","description":"Type-safe Firestore models for Next.js (App Router): server-only firebase-admin models, a memoized admin singleton, and an RSC serialization bridge. The Next.js runtime of the Fireclass suite.","directories":{},"sideEffects":false,"_nodeVersion":"24.15.0","dependencies":{"server-only":"^0.0.1","@dharayush7/fireclass-js":"^2.0.8"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"next":"^15.1.3","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":{"next":"^13.4.0 || ^14.0.0 || ^15.0.0","firebase-admin":"^12.0.0 || ^13.0.0","class-validator":"^0.14.0","class-transformer":"^0.5.0"},"peerDependenciesMeta":{"next":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/fireclass-ssr_2.0.8_1783612209336_0.5294136189890082","host":"s3://npm-registry-packages-npm-production"}},"2.0.9":{"name":"@dharayush7/fireclass-ssr","version":"2.0.9","description":"Type-safe Firestore ODM for Next.js App Router with Firebase Admin, server-only models, memoized initialization, Server Actions, and RSC serialization.","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-ssr.git"},"homepage":"https://fireclass.ayushdhar.com/docs/api/ssr","bugs":{"url":"https://github.com/dharayush7/fireclass-ssr/issues"},"keywords":["fireclass","firestore","firebase","firebase-admin","firestore-orm","firebase-orm","typescript-orm","odm","object-document-mapper","firestore-model","typed-firestore","firestore-typescript","nextjs","next-js","app-router","rsc","react-server-components","server-components","server-actions","ssr","server-only","serverless","vercel","orm","typescript","type-safe","validation","query-builder","serialization"],"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"},"./client":{"types":"./dist/client.d.ts","import":"./dist/client.js","require":"./dist/client.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"},"dependencies":{"@dharayush7/fireclass-js":"^2.0.8","server-only":"^0.0.1"},"peerDependencies":{"class-transformer":"^0.5.0","class-validator":"^0.14.0","firebase-admin":"^12.0.0 || ^13.0.0","next":"^13.4.0 || ^14.0.0 || ^15.0.0"},"peerDependenciesMeta":{"next":{"optional":true}},"devDependencies":{"@types/node":"^24.13.3","class-transformer":"^0.5.1","class-validator":"^0.14.3","firebase-admin":"^13.6.0","next":"^15.1.3","reflect-metadata":"^0.2.2","tsup":"^8.5.1","typescript":"^5.9.3","vitest":"^2.1.9"},"publishConfig":{"access":"public"},"gitHead":"b3548285c60d6317f74ee213a29da0849b4b241e","_id":"@dharayush7/fireclass-ssr@2.0.9","_nodeVersion":"24.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-786aY1QI86WoAMrRLqXGk+SIT1pIg7tyBQccVMFjyxEkInG/af3aT54yW8PS0zvM51aUfelqdmMjXaTY1l3A7g==","shasum":"1220bf3e536056c84ec64e052b56bbbe9d1f95d6","tarball":"https://registry.npmjs.org/@dharayush7/fireclass-ssr/-/fireclass-ssr-2.0.9.tgz","fileCount":19,"unpackedSize":63576,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDVTfqfSY56GfWAEsVR/5WHg5vRkLNbfo+5oiz392V3sgIgJa24HLKLqVh7INexyg5kGBsogoP8m7kWSsnNp/6zOy8="}]},"_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-ssr_2.0.9_1783701043884_0.15458772862207248"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-09T15:50:08.953Z","modified":"2026-07-10T16:30:44.144Z","2.0.8":"2026-07-09T15:50:09.490Z","2.0.9":"2026-07-10T16:30:44.026Z"},"bugs":{"url":"https://github.com/dharayush7/fireclass-ssr/issues"},"author":{"name":"Ayush Dhar","email":"contact@ayushdhar.com","url":"https://www.ayushdhar.com"},"license":"MIT","homepage":"https://fireclass.ayushdhar.com/docs/api/ssr","keywords":["fireclass","firestore","firebase","firebase-admin","firestore-orm","firebase-orm","typescript-orm","odm","object-document-mapper","firestore-model","typed-firestore","firestore-typescript","nextjs","next-js","app-router","rsc","react-server-components","server-components","server-actions","ssr","server-only","serverless","vercel","orm","typescript","type-safe","validation","query-builder","serialization"],"repository":{"type":"git","url":"git+https://github.com/dharayush7/fireclass-ssr.git"},"description":"Type-safe Firestore ODM for Next.js App Router with Firebase Admin, server-only models, memoized initialization, Server Actions, and RSC serialization.","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-ssr</h1>\n\n<p align=\"center\">\n  Type-safe Firestore models for Next.js App Router with Firebase Admin, server-only boundaries, Server Actions, and RSC serialization.\n</p>\n\n<p align=\"center\">\n  <a href=\"https://fireclass.ayushdhar.com/docs/installation/nextjs\">Setup</a> |\n  <a href=\"https://fireclass.ayushdhar.com/docs/api/ssr\">API reference</a> |\n  <a href=\"https://fireclass.ayushdhar.com/docs/guides/nextjs\">App Router guide</a> |\n  <a href=\"https://github.com/dharayush7/fireclass-ssr\">GitHub</a> |\n  <a href=\"https://www.npmjs.com/package/@dharayush7/fireclass-ssr\">npm</a>\n</p>\n\n<code>@dharayush7/fireclass-ssr</code> is the Fireclass runtime for Next.js App\nRouter. It combines the Firebase Admin model API with memoized initialization,\nServer Action error handling, and a React Server Component serialization bridge.\n\n## Runtime boundaries\n\n| Import | Environment | Purpose |\n| --- | --- | --- |\n| <code>@dharayush7/fireclass-ssr</code> | Server Components, Route Handlers, Server Actions | Models, Firebase Admin, actions, and serialization |\n| <code>@dharayush7/fireclass-ssr/client</code> | Client Components | Pure serialization types and date revival only |\n\n> **Never import the root entry in a Client Component.** It imports\n> <code>server-only</code> and Firebase Admin. Use the <code>/client</code>\n> entry for <code>Serialized</code>, <code>serialize</code>,\n> <code>serializeList</code>, and <code>reviveDates</code>.\n\n## Installation\n\n~~~bash\nnpm install @dharayush7/fireclass-ssr firebase-admin class-validator class-transformer reflect-metadata server-only\n~~~\n\nEnable decorators in the TypeScript configuration that compiles models:\n\n~~~jsonc\n{\n  \"compilerOptions\": {\n    \"experimentalDecorators\": true,\n    \"emitDecoratorMetadata\": true\n  }\n}\n~~~\n\n## Firebase credentials\n\nFor local development, add service-account values to a gitignored\n<code>.env.local</code>:\n\n~~~bash\nFIREBASE_PROJECT_ID=your-project-id\nFIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com\nFIREBASE_PRIVATE_KEY=\"-----BEGIN PRIVATE KEY-----\\n...\\n-----END PRIVATE KEY-----\\n\"\n~~~\n\nCredential resolution order is:\n\n1. Explicit <code>serviceAccount</code> passed to <code>getFireclass</code> or\n   <code>initFireclassAdmin</code>.\n2. <code>FIREBASE_PROJECT_ID</code>, <code>FIREBASE_CLIENT_EMAIL</code>, and\n   <code>FIREBASE_PRIVATE_KEY</code>.\n3. Fallback aliases <code>PROJECT_ID</code>, <code>CLIENT_EMAIL</code>, and\n   <code>PRIVATE_KEY</code>.\n4. Application Default Credentials.\n\nEscaped <code>\\n</code> sequences in private keys are restored automatically.\n\n> **No separate Firebase file is recommended.** Fireclass owns the memoized\n> Firebase Admin initialization through <code>getFireclass()</code>.\n\n## Create the server binding\n\n~~~ts\n// src/lib/fireclass.server.ts\nimport \"reflect-metadata\";\nimport \"server-only\";\nimport { getFireclass } from \"@dharayush7/fireclass-ssr\";\n\nexport const { BaseModel, adapter } = getFireclass();\n~~~\n\nOnly initialized values belong in this local file. Import\n<code>Collection</code>, <code>serializeList</code>,\n<code>runAction</code>, and other standalone helpers directly from the SDK.\n\n## Define a server-only model\n\n~~~ts\n// src/models/post.ts\nimport \"server-only\";\nimport { Collection } from \"@dharayush7/fireclass-ssr\";\nimport { IsDate, IsString, Length } from \"class-validator\";\nimport { Type } from \"class-transformer\";\nimport { BaseModel } from \"../lib/fireclass.server\";\n\n@Collection(\"posts\")\nexport class Post extends BaseModel<Post> {\n  @IsString()\n  @Length(1, 120)\n  title!: string;\n\n  @IsDate()\n  @Type(() => Date)\n  createdAt!: Date;\n\n  constructor(data?: Partial<Post>) {\n    super(data);\n    Object.assign(this, data);\n  }\n}\n~~~\n\n## Read in a Server Component\n\n~~~tsx\n// src/app/posts/page.tsx\nimport { serializeList } from \"@dharayush7/fireclass-ssr\";\nimport { Post } from \"@/models/post\";\nimport { PostList } from \"./post-list\";\n\nexport const dynamic = \"force-dynamic\";\n\nexport default async function PostsPage() {\n  const posts = await Post.findMany({\n    orderBy: { createdAt: \"desc\" },\n    limit: 50,\n  });\n\n  return <PostList initial={serializeList(posts)} />;\n}\n~~~\n\n## Receive data in a Client Component\n\n~~~tsx\n// src/app/posts/post-list.tsx\n\"use client\";\n\nimport {\n  reviveDates,\n  type Serialized,\n} from \"@dharayush7/fireclass-ssr/client\";\n\ninterface PostShape {\n  id?: string;\n  title: string;\n  createdAt: Date;\n}\n\nexport function PostList({\n  initial,\n}: {\n  initial: Serialized<PostShape>[];\n}) {\n  return (\n    <ul>\n      {initial.map((value) => {\n        const post = reviveDates(value, [\"createdAt\"]);\n        return (\n          <li key={post.id}>\n            {post.title} - {post.createdAt.toLocaleDateString()}\n          </li>\n        );\n      })}\n    </ul>\n  );\n}\n~~~\n\n## Mutate with a Server Action\n\n~~~ts\n// src/app/posts/actions.ts\n\"use server\";\n\nimport {\n  runAction,\n  serialize,\n} from \"@dharayush7/fireclass-ssr\";\nimport { revalidatePath } from \"next/cache\";\nimport { Post } from \"@/models/post\";\n\nexport async function createPost(formData: FormData) {\n  const result = await runAction(async () => {\n    const post = new Post({\n      title: String(formData.get(\"title\") ?? \"\"),\n      createdAt: new Date(),\n    });\n\n    await post.save();\n    return serialize(post);\n  });\n\n  if (result.ok) {\n    revalidatePath(\"/posts\");\n  }\n\n  return result;\n}\n~~~\n\n<code>runAction</code> returns:\n\n~~~ts\ntype ActionResult<T> =\n  | { ok: true; data: T }\n  | { ok: false; error: string; details?: ActionFieldError[] };\n~~~\n\nValidation and other Fireclass errors become serializable results. Non-Fireclass\nerrors are re-thrown for Next.js error handling.\n\n## Export index\n\n| Export | Purpose |\n| --- | --- |\n| <code>getFireclass(options?)</code> | Return the process-global <code>BaseModel</code> and <code>AdminAdapter</code> binding |\n| <code>initFireclassAdmin(options?)</code> | Initialize and cache Admin Firestore |\n| <code>resetFireclassAdmin()</code> | Clear Fireclass Admin references for isolated tests |\n| <code>FireclassAdminOptions</code> | Explicit credentials and project id |\n| <code>runAction(fn)</code> | Convert Fireclass errors into <code>ActionResult</code> |\n| <code>serialize(model)</code> | Convert one model to an RSC-safe plain object |\n| <code>serializeList(models)</code> | Convert a model list |\n| <code>reviveDates(value, keys)</code> | Convert selected top-level ISO strings back to Date |\n| <code>Serialized</code> | Recursive serialized model type |\n| Node and core exports | Models, decorators, queries, adapters, validation, and errors |\n\n### Initialization behavior\n\nThe first <code>getFireclass()</code> call initializes Firebase Admin and\ncreates the adapter. Later calls return the same object; later options do not\nreplace the cached binding.\n\n<code>initFireclassAdmin()</code> reuses an existing Firebase Admin app when one\nexists. <code>resetFireclassAdmin()</code> clears Fireclass's Admin references\nbut does not delete Firebase Admin apps or clear an already-created\n<code>getFireclass()</code> binding.\n\n### Serialization behavior\n\n<code>serialize</code> copies own enumerable fields and recursively converts\nDate values to ISO strings. Prototype methods are excluded.\n\n<code>reviveDates</code> creates a shallow copy and converts only selected\ntop-level string fields. It does not traverse nested paths.\n\n## CLI setup\n\nRun the CLI after credentials exist:\n\n~~~bash\nnpx fireclass init\nnpx fireclass doctor\nnpm run build\n~~~\n\nChoose Next.js App Router. The CLI writes <code>fireclass.json</code>, a\nserver-only Fireclass entry, environment templates, decorator flags, and a\nstarter model. It uses <code>firebase: null</code> because this SDK owns Admin\ninitialization.\n\n## Documentation and examples\n\n- [Next.js installation](https://fireclass.ayushdhar.com/docs/installation/nextjs)\n- [Complete SSR API](https://fireclass.ayushdhar.com/docs/api/ssr)\n- [Next.js App Router guide](https://fireclass.ayushdhar.com/docs/guides/nextjs)\n- [Core model API](https://fireclass.ayushdhar.com/docs/api/core)\n- [Runnable Next.js application](https://github.com/dharayush7/fireclass-cli/tree/main/example/fireclass-next-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"}