{"_id":"@asaidimu/remote-store-firebase","name":"@asaidimu/remote-store-firebase","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@asaidimu/remote-store-firebase","version":"1.0.0","description":"A Firebase adapter for the remote-store library that provides a consistent interface for working with Firestore collections and Firebase Storage.","main":"index.js","types":"index.d.ts","keywords":["react-query","react","firebase","typescript"],"author":{"name":"Saidimu","email":"47994458+asaidimu@users.noreply.github.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/asaidimu/remote-store.git"},"bugs":{"url":"https://github.com/asaidimu/remote-store/issues"},"homepage":"https://github.com/asaidimu/remote-store#readme","publishConfig":{"registry":"https://registry.npmjs.org/","tag":"latest","access":"public"},"dependencies":{"@tanstack/react-query":"^5.63.0","firebase":"^11.1.0"},"_id":"@asaidimu/remote-store-firebase@1.0.0","gitHead":"c8bb8ec4eb11bbc9e8c8f4d68e9eff2625847676","_nodeVersion":"20.8.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-x98uDgu0PJpgVGEuY8o0KVJI2JFyvUPb9QhFa56nlc2/wOCzb36tHXUFPN8qcrX3HIrY/5NbmpU3CPC4DNyknA==","shasum":"27589701d8ed353daf6bce64d511473f7b220ed8","tarball":"https://registry.npmjs.org/@asaidimu/remote-store-firebase/-/remote-store-firebase-1.0.0.tgz","fileCount":5,"unpackedSize":10213,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHPejSKEMY1zdLD6ZqTdKwSUTVa+6IaKSy696/XFSObTAiEAhwG2yNzt/eXqKJACrt8M/XqcuHzlNaoE9UW2wYm1/W4="}]},"_npmUser":{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"},"directories":{},"maintainers":[{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/remote-store-firebase_1.0.0_1736589171234_0.09624923306505173"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-11T09:52:51.086Z","1.0.0":"2025-01-11T09:52:51.416Z","modified":"2025-01-11T09:52:51.736Z"},"maintainers":[{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"}],"description":"A Firebase adapter for the remote-store library that provides a consistent interface for working with Firestore collections and Firebase Storage.","homepage":"https://github.com/asaidimu/remote-store#readme","keywords":["react-query","react","firebase","typescript"],"repository":{"type":"git","url":"git+https://github.com/asaidimu/remote-store.git"},"author":{"name":"Saidimu","email":"47994458+asaidimu@users.noreply.github.com"},"bugs":{"url":"https://github.com/asaidimu/remote-store/issues"},"license":"MIT","readme":"# @asaidimu/remote-store-firebase\n\nA Firebase adapter for the remote-store library that provides a consistent interface for working with Firestore collections and Firebase Storage.\n\n## Installation\n\n```bash\nnpm install @asaidimu/remote-store-firebase firebase\n```\n\n## Usage\n\n```typescript\nimport { initializeApp } from 'firebase/app';\nimport { getFirestore } from 'firebase/firestore';\nimport { getStorage } from 'firebase/storage';\nimport { createFirebaseStore } from '@asaidimu/remote-store-firebase';\n\n// Initialize Firebase\nconst app = initializeApp({\n  // your firebase config\n});\n\nconst db = getFirestore(app);\nconst storage = getStorage(app);\n\n// Define your record type\ninterface User extends RemoteStoreRecord {\n  name: string;\n  email: string;\n  photoURL?: string;\n}\n\n// Create a store instance\nconst userStore = createFirebaseStore<User>({\n  collectionName: 'users',\n  db,\n  storage\n});\n\n// Use the store\nasync function example() {\n  // Create a user\n  const user = await userStore.create({\n    data: {\n      name: 'John Doe',\n      email: 'john@example.com',\n    }\n  });\n\n  // Upload a profile photo\n  const photoFile = new File([''], 'profile.png');\n  await userStore.upload({\n    id: user.id,\n    field: 'photoURL',\n    file: photoFile\n  });\n\n  // List users with pagination\n  const users = await userStore.list({\n    page: 1,\n    pageSize: 20,\n    filter: 'name=John Doe'\n  });\n}\n```\n\n## API\n\n### `createFirebaseStore(options)`\n\nCreates a new store instance for interacting with a Firestore collection.\n\n#### Options\n\n- `collectionName: string` - The name of the Firestore collection\n- `db?: Firestore` - An initialized Firestore instance (optional, defaults to default app instance)\n- `storage?: Storage` - An initialized Firebase Storage instance (optional, defaults to default app instance)\n\n#### Returns\n\nReturns a `BaseStore<T>` instance with the following methods:\n\n- `find({ filter, options? })` - Find first record matching the filter\n- `read({ id })` - Read a record by ID\n- `list({ filter?, page?, pageSize?, ...options })` - List records with pagination\n- `create({ data })` - Create a new record\n- `update({ id, data })` - Update an existing record\n- `delete({ id })` - Delete a record\n- `upload({ id, field, file })` - Upload a file to storage and update record with URL\n\n### Type Conversion\n\nThe adapter includes a built-in `FirestoreDataConverter` that automatically handles converting your TypeScript types to and from Firestore DocumentData. The converter:\n\n- Strips the `id` field when saving to Firestore (since Firestore manages document IDs)\n- Adds the document ID as the `id` field when reading from Firestore\n- Maintains type safety throughout the conversion process\n\n### Pagination\n\nThe Firebase adapter implements pagination using Firestore's native query constraints:\n\n- Records are ordered by `id` by default to ensure consistent pagination\n- The `pageSize` option is implemented using Firestore's `limit()` constraint\n- For real-world applications, you may want to implement cursor-based pagination using `startAfter()` for better performance with large datasets\n\n### Error Handling\n\nAll methods include consistent error handling that:\n\n- Preserves the original error message\n- Adds context about the operation that failed\n- Maintains type safety with the error object\n\n## License\n\nMIT\n","readmeFilename":"README.md"}