@umituz/react-native-firebase 1.13.58 → 1.13.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +277 -0
  2. package/package.json +10 -5
  3. package/scripts/README.md +513 -0
  4. package/src/auth/README.md +339 -0
  5. package/src/auth/domain/README.md +264 -0
  6. package/src/auth/domain/errors/README.md +291 -0
  7. package/src/auth/infrastructure/config/README.md +239 -0
  8. package/src/auth/infrastructure/config/initializers/FirebaseAuthInitializer.ts +1 -1
  9. package/src/auth/infrastructure/services/README.md +346 -0
  10. package/src/auth/infrastructure/stores/README.md +407 -0
  11. package/src/auth/infrastructure/stores/auth.store.ts +1 -1
  12. package/src/auth/presentation/hooks/README.md +442 -0
  13. package/src/auth/presentation/hooks/useAnonymousAuth.ts +4 -4
  14. package/src/auth/presentation/hooks/utils/auth-state-change.handler.ts +1 -1
  15. package/src/domain/README.md +628 -0
  16. package/src/firestore/README.md +566 -0
  17. package/src/firestore/domain/README.md +325 -0
  18. package/src/firestore/domain/constants/README.md +332 -0
  19. package/src/firestore/domain/entities/README.md +286 -0
  20. package/src/firestore/domain/errors/README.md +389 -0
  21. package/src/firestore/infrastructure/config/FirestoreClient.ts +1 -1
  22. package/src/firestore/infrastructure/config/README.md +239 -0
  23. package/src/firestore/infrastructure/middleware/README.md +316 -0
  24. package/src/firestore/infrastructure/repositories/BaseRepository.ts +1 -1
  25. package/src/firestore/infrastructure/repositories/README.md +425 -0
  26. package/src/firestore/infrastructure/services/README.md +332 -0
  27. package/src/firestore/infrastructure/services/RequestLoggerService.ts +4 -4
  28. package/src/firestore/types/pagination/README.md +332 -0
  29. package/src/firestore/utils/README.md +574 -0
  30. package/src/firestore/utils/dateUtils/README.md +171 -0
  31. package/src/firestore/utils/document-mapper.helper/README.md +309 -0
  32. package/src/firestore/utils/pagination.helper/README.md +298 -0
  33. package/src/firestore/utils/path-resolver/README.md +277 -0
  34. package/src/firestore/utils/query-builder/README.md +291 -0
  35. package/src/firestore/utils/quota-error-detector/README.md +355 -0
  36. package/src/infrastructure/README.md +408 -0
  37. package/src/infrastructure/config/FirebaseClient.ts +1 -1
  38. package/src/infrastructure/config/README.md +262 -0
  39. package/src/presentation/README.md +556 -0
  40. package/src/storage/README.md +493 -0
  41. package/src/storage/deleter/README.md +370 -0
  42. package/src/storage/types/README.md +313 -0
  43. package/src/storage/uploader/README.md +409 -0
@@ -0,0 +1,425 @@
1
+ # Firestore Repositories
2
+
3
+ Repository pattern implementation for Firestore database operations providing base classes for CRUD, queries, and pagination.
4
+
5
+ ## Purpose
6
+
7
+ Provides a hierarchical repository system for Firestore operations with three levels: BaseRepository (basic CRUD), BaseQueryRepository (advanced querying), and BasePaginatedRepository (pagination support).
8
+
9
+ ## For AI Agents
10
+
11
+ ### Before Using Repositories
12
+
13
+ 1. **ALWAYS** extend appropriate base repository class
14
+ 2. **IMPLEMENT** buildQuery() method for query repositories
15
+ 3. **USE** types for entities and options
16
+ 4. **NEVER** call Firebase Firestore directly in application code
17
+ 5. **REGISTER** middleware in repository constructor
18
+
19
+ ### Required Practices
20
+
21
+ 1. **Extend base repository** - Always extend BaseRepository, BaseQueryRepository, or BasePaginatedRepository
22
+ 2. **Implement buildQuery()** - For query/paginated repositories, must implement this abstract method
23
+ 3. **Use types** - Define entity type and options type as generics
24
+ 4. **Register middleware** - Add middleware in constructor for cross-cutting concerns
25
+ 5. **Return PaginatedResult** - For paginated repositories, use PaginatedResult<T> type
26
+
27
+ ### Forbidden Practices
28
+
29
+ ## ❌ NEVER
30
+
31
+ - Use Firebase Firestore SDK directly in application code
32
+ - Skip implementing buildQuery() in query repositories
33
+ - Use `any` type for entity or options
34
+ - Create repositories without extending base classes
35
+ - Mix pagination strategies (cursor vs offset)
36
+ - Query without proper indexes
37
+
38
+ ## ⚠️ Avoid
39
+
40
+ - Complex query logic in buildQuery() method
41
+ - Not using middleware for cross-cutting concerns
42
+ - Fetching entire collections without pagination
43
+ - Not handling empty query results
44
+ - Ignoring composite index requirements
45
+
46
+ ## Usage Strategies
47
+
48
+ ### For Basic CRUD Operations
49
+
50
+ **Strategy:** Extend BaseRepository for simple collection operations.
51
+
52
+ **Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/repositories`
53
+
54
+ **When to Use:**
55
+ - Simple collections without complex queries
56
+ - Basic CRUD operations only
57
+ - Small datasets (< 100 documents)
58
+ - No pagination needed
59
+
60
+ **Available Methods:**
61
+ - `findById(id)` - Get document by ID
62
+ - `create(data)` - Create new document
63
+ - `update(id, data)` - Update document
64
+ - `delete(id)` - Delete document
65
+ - `getAll()` - Get all documents
66
+ - `exists(id)` - Check if document exists
67
+ - `getCollection()` - Get Firestore collection reference
68
+
69
+ **Implementation:**
70
+ 1. Extend BaseRepository<TEntity>
71
+ 2. Pass collection name to super()
72
+ 3. Add custom methods if needed
73
+ 4. Use in services or hooks
74
+
75
+ ### For Advanced Queries
76
+
77
+ **Strategy:** Extend BaseQueryRepository for filtering, sorting, and querying.
78
+
79
+ **Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/repositories`
80
+
81
+ **When to Use:**
82
+ - Need where clauses and filtering
83
+ - Require sorting and ordering
84
+ - Need limit queries
85
+ - Complex query conditions
86
+
87
+ **Available Methods:**
88
+ - All BaseRepository methods
89
+ - `find(options)` - Find documents matching options
90
+ - `findFirst(options)` - Get first matching document
91
+ - `count(options)` - Count matching documents
92
+ - `buildQuery(options)` - Build Firestore query (abstract)
93
+
94
+ **Implementation Strategy:**
95
+ 1. Extend BaseQueryRepository<TEntity, TOptions>
96
+ 2. Define TOptions interface for query parameters
97
+ 3. Implement buildQuery() method
98
+ 4. Use QueryBuilder helper if needed
99
+ 5. Add custom query methods
100
+
101
+ **buildQuery() Implementation Order (REQUIRED):**
102
+ 1. Get base collection: `this.getCollection()`
103
+ 2. Apply where clauses (all filters first)
104
+ 3. Apply orderBy (sorting)
105
+ 4. Apply limit (last step)
106
+ 5. Return query
107
+
108
+ ### For Pagination
109
+
110
+ **Strategy:** Extend BasePaginatedRepository for cursor-based pagination.
111
+
112
+ **Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/repositories`
113
+
114
+ **When to Use:**
115
+ - Large datasets (> 100 documents)
116
+ - Infinite scroll implementations
117
+ - Mobile applications
118
+ - Performance optimization
119
+
120
+ **Available Methods:**
121
+ - All BaseQueryRepository methods
122
+ - `paginate(params)` - Fetch page with cursor
123
+ - `buildQuery(options, cursor?)` - Build query with cursor
124
+
125
+ **Pagination Strategy:**
126
+ 1. Fetch `pageSize + 1` documents
127
+ 2. If returned > pageSize, hasMore = true
128
+ 3. Return only pageSize documents
129
+ 4. Use last document as cursor for next page
130
+ 5. Stop when hasMore is false
131
+
132
+ **Implementation:**
133
+ 1. Extend BasePaginatedRepository<TEntity, TOptions>
134
+ 2. Implement buildQuery() with cursor parameter
135
+ 3. Use `startAfter(cursor)` when cursor provided
136
+ 4. Return PaginatedResult<TEntity> from paginate()
137
+ 5. Store nextCursor in UI state
138
+
139
+ ### For Middleware Integration
140
+
141
+ **Strategy:** Register middleware in repository constructor for cross-cutting concerns.
142
+
143
+ **Import From:** `@umituz/react-native-firebase/firestore` infrastructure/middleware
144
+
145
+ **Available Middleware:**
146
+ - `quotaTrackingMiddleware` - Track Firestore quota usage
147
+ - `queryDeduplicationMiddleware` - Deduplicate identical queries
148
+ - `errorHandlingMiddleware` - Centralized error handling
149
+ - `loggingMiddleware` - Log all repository operations
150
+
151
+ **Registration Strategy:**
152
+ 1. Import middleware functions
153
+ 2. Call `this.registerMiddleware()` in constructor
154
+ 3. Middleware executes in registration order
155
+ 4. Use for quota tracking, caching, etc.
156
+
157
+ ## Repository Hierarchy
158
+
159
+ ### BaseRepository
160
+
161
+ **Purpose:** Basic CRUD operations for single collections
162
+
163
+ **Import From:** `src/firestore/infrastructure/repositories/base-repository`
164
+
165
+ **Provides:**
166
+ - findById, create, update, delete
167
+ - getAll, exists
168
+ - getCollection (raw access)
169
+
170
+ **Generic Types:**
171
+ - `TEntity` - Document entity type
172
+
173
+ **Usage:** Simple collections without queries
174
+
175
+ ### BaseQueryRepository
176
+
177
+ **Purpose:** Advanced querying with filtering and sorting
178
+
179
+ **Import From:** `src/firestore/infrastructure/repositories/base-query-repository`
180
+
181
+ **Extends:** BaseRepository
182
+
183
+ **Adds:**
184
+ - find(options) - Multiple documents
185
+ - findFirst(options) - Single document
186
+ - count(options) - Count matches
187
+ - buildQuery(options) - Abstract method
188
+
189
+ **Generic Types:**
190
+ - `TEntity` - Document entity type
191
+ - `TOptions` - Query options type
192
+
193
+ **Requires:** Implementation of buildQuery()
194
+
195
+ ### BasePaginatedRepository
196
+
197
+ **Purpose:** Cursor-based pagination for large datasets
198
+
199
+ **Import From:** `src/firestore/infrastructure/repositories/base-paginated-repository`
200
+
201
+ **Extends:** BaseQueryRepository
202
+
203
+ **Adds:**
204
+ - paginate(params) - Fetch page
205
+ - buildQuery(options, cursor?) - With cursor support
206
+
207
+ **Generic Types:**
208
+ - `TEntity` - Document entity type
209
+ - `TOptions` - Query options type
210
+
211
+ **Requires:** Implementation of buildQuery() with cursor
212
+
213
+ ## Query Building Strategy
214
+
215
+ ### buildQuery() Method
216
+
217
+ **Purpose:** Construct Firestore query from options
218
+
219
+ **Import From:** Extend from base repository
220
+
221
+ **Required Order:**
222
+ 1. Get collection reference
223
+ 2. Apply all where clauses
224
+ 3. Apply orderBy (single field)
225
+ 4. Apply limit
226
+ 5. Return query
227
+
228
+ **Firestore Limitations:**
229
+ - Only one orderBy per query
230
+ - Range filters (>, >=, <, <=) require first field to be orderBy
231
+ - Composite indexes needed for queries with multiple filters + orderBy
232
+ - No native full-text search
233
+
234
+ **Query Building:**
235
+ - Use QueryBuilder helper for complex queries
236
+ - Import from: `src/firestore/utils/query-builder`
237
+ - Ensures correct order
238
+ - Validates query constraints
239
+
240
+ ## Middleware System
241
+
242
+ ### Middleware Pattern
243
+
244
+ **Strategy:** Register middleware functions in repository constructor.
245
+
246
+ **Import From:** `src/firestore/infrastructure/middleware`
247
+
248
+ **Middleware Function Signature:**
249
+ - Receives context (collection, operation, options)
250
+ - Returns modified context or throws error
251
+ - Executes in registration order
252
+
253
+ **Common Middleware Use Cases:**
254
+ - Quota tracking (count reads/writes)
255
+ - Query deduplication (cache identical queries)
256
+ - Error handling (transform errors)
257
+ - Logging (track operations)
258
+
259
+ **Registration:**
260
+ 1. Import middleware from infrastructure/middleware
261
+ 2. Call `this.registerMiddleware(middlewareFunc)` in constructor
262
+ 3. Middleware auto-executes on all operations
263
+
264
+ ## Common Mistakes to Avoid
265
+
266
+ 1. ❌ Not implementing buildQuery() in query repositories
267
+ - ✅ Always implement abstract buildQuery() method
268
+
269
+ 2. ❌ Using offset-based pagination
270
+ - ✅ Use cursor-based pagination (startAfter)
271
+
272
+ 3. ❌ Querying without indexes
273
+ - ✅ Create composite indexes in Firebase Console
274
+
275
+ 4. ❌ Fetching entire collections
276
+ - ✅ Use pagination for large datasets
277
+
278
+ 5. ❌ Ignoring middleware
279
+ - ✅ Register middleware for cross-cutting concerns
280
+
281
+ 6. ❌ Complex query logic in components
282
+ - ✅ Add custom query methods to repository
283
+
284
+ 7. ❌ Wrong query building order
285
+ - ✅ where → orderBy → limit (strict order)
286
+
287
+ ## AI Agent Instructions
288
+
289
+ ### When Creating New Repository
290
+
291
+ 1. Choose appropriate base class (Base, Query, or Paginated)
292
+ 2. Define TEntity interface (document structure)
293
+ 3. Define TOptions interface (if query/paginated)
294
+ 4. Extend base repository with generics
295
+ 5. Implement buildQuery() if needed
296
+ 6. Add custom methods for common queries
297
+ 7. Register middleware in constructor
298
+ 8. Export repository instance
299
+
300
+ ### When Adding Query Method
301
+
302
+ 1. Determine if should use find() or custom method
303
+ 2. For simple queries: Use find() with options
304
+ 3. For complex queries: Add custom method to repository
305
+ 4. Use buildQuery() in custom methods
306
+ 5. Return appropriate type (T, T[], PaginatedResult<T>)
307
+ 6. Document query purpose and parameters
308
+
309
+ ### When Implementing buildQuery()
310
+
311
+ 1. Start with `this.getCollection()`
312
+ 2. Apply where clauses for all filters
313
+ 3. Apply orderBy for sorting
314
+ 4. Apply limit for result size
315
+ 5. Apply startAfter(cursor) if paginating
316
+ 6. Return final Query object
317
+ 7. Follow strict order (where → orderBy → limit)
318
+
319
+ ### When Adding Middleware
320
+
321
+ 1. Import middleware from infrastructure/middleware
322
+ 2. Register in constructor using `this.registerMiddleware()`
323
+ 3. Consider execution order (register in desired order)
324
+ 4. Test middleware execution
325
+ 5. Handle middleware errors appropriately
326
+
327
+ ## Code Quality Standards
328
+
329
+ ### TypeScript
330
+
331
+ - Always specify generic types <TEntity> and <TOptions>
332
+ - Export TEntity and TOptions interfaces
333
+ - Use strict null checks
334
+ - Never use `any` type
335
+
336
+ ### File Organization
337
+
338
+ - One repository per entity
339
+ - Repository in infrastructure/repositories
340
+ - Entity types in domain/entities
341
+ - Custom options types near repository
342
+
343
+ ### Method Naming
344
+
345
+ - Use `findBy` prefix for query methods
346
+ - Use `get` prefix for single fetch
347
+ - Use `count` prefix for counting
348
+ - Use `is` prefix for boolean checks
349
+
350
+ ## Performance Considerations
351
+
352
+ ### Query Optimization
353
+
354
+ **Use Indexes:**
355
+ - Create composite indexes for complex queries
356
+ - Firestore auto-suggests missing indexes
357
+ - Index required for: where + orderBy queries
358
+
359
+ **Limit Results:**
360
+ - Always use limit() on queries
361
+ - Pagination for large collections
362
+ - Avoid getAll() on large datasets
363
+
364
+ **Pagination vs Offset:**
365
+ - Use cursor-based (startAfter)
366
+ - Never use offset-based pagination
367
+ - More scalable and performant
368
+
369
+ ### Middleware Overhead
370
+
371
+ - Minimal performance impact
372
+ - Middleware executes synchronously
373
+ - Keep middleware functions lightweight
374
+ - Avoid async operations in middleware
375
+
376
+ ## Related Documentation
377
+
378
+ - [Firestore Module README](../../README.md)
379
+ - [Pagination Helper README](../../utils/pagination.helper/README.md)
380
+ - [Query Builder README](../../utils/query-builder/README.md)
381
+ - [Middleware README](../middleware/README.md)
382
+ - [Type Definitions README](../../types/pagination/README.md)
383
+
384
+ ## API Reference
385
+
386
+ ### BaseRepository
387
+
388
+ **Import From:** `src/firestore/infrastructure/repositories/base-repository`
389
+
390
+ | Method | Return Type | Description |
391
+ |--------|-------------|-------------|
392
+ | `constructor(collectionName)` | - | Initialize with collection name |
393
+ | `findById(id)` | `Promise<T \| null>` | Get document by ID |
394
+ | `create(data)` | `Promise<T>` | Create document |
395
+ | `update(id, data)` | `Promise<void>` | Update document |
396
+ | `delete(id)` | `Promise<void>` | Delete document |
397
+ | `getAll()` | `Promise<T[]>` | Get all documents |
398
+ | `exists(id)` | `Promise<boolean>` | Check if document exists |
399
+ | `getCollection()` | `CollectionReference` | Get raw collection reference |
400
+
401
+ ### BaseQueryRepository
402
+
403
+ **Import From:** `src/firestore/infrastructure/repositories/base-query-repository`
404
+
405
+ | Method | Return Type | Description |
406
+ |--------|-------------|-------------|
407
+ | `find(options)` | `Promise<T[]>` | Find matching documents |
408
+ | `findFirst(options)` | `Promise<T \| null>` | Get first match |
409
+ | `count(options)` | `Promise<number>` | Count matches |
410
+ | `buildQuery(options)` | `Query` | Build query (abstract) |
411
+ | `registerMiddleware(middleware)` | `void` | Register middleware |
412
+
413
+ ### BasePaginatedRepository
414
+
415
+ **Import From:** `src/firestore/infrastructure/repositories/base-paginated-repository`
416
+
417
+ | Method | Return Type | Description |
418
+ |--------|-------------|-------------|
419
+ | `paginate(params)` | `Promise<PaginatedResult<T>>` | Fetch page |
420
+ | `buildQuery(options, cursor?)` | `Query` | Build query with cursor (abstract) |
421
+
422
+ ---
423
+
424
+ **Last Updated:** 2025-01-08
425
+ **Maintainer:** Firestore Module Team