@umituz/react-native-firebase 1.13.57 → 1.13.59
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.
- package/README.md +277 -0
- package/package.json +1 -1
- package/scripts/README.md +513 -0
- package/src/auth/README.md +339 -0
- package/src/auth/domain/README.md +264 -0
- package/src/auth/domain/errors/README.md +291 -0
- package/src/auth/infrastructure/config/README.md +239 -0
- package/src/auth/infrastructure/services/README.md +346 -0
- package/src/auth/infrastructure/stores/README.md +407 -0
- package/src/auth/presentation/hooks/README.md +442 -0
- package/src/domain/README.md +628 -0
- package/src/firestore/README.md +566 -0
- package/src/firestore/domain/README.md +325 -0
- package/src/firestore/domain/constants/README.md +332 -0
- package/src/firestore/domain/entities/README.md +286 -0
- package/src/firestore/domain/errors/README.md +389 -0
- package/src/firestore/infrastructure/config/README.md +239 -0
- package/src/firestore/infrastructure/middleware/README.md +316 -0
- package/src/firestore/infrastructure/repositories/README.md +425 -0
- package/src/firestore/infrastructure/services/README.md +332 -0
- package/src/firestore/types/pagination/README.md +332 -0
- package/src/firestore/utils/README.md +574 -0
- package/src/firestore/utils/dateUtils/README.md +171 -0
- package/src/firestore/utils/document-mapper.helper/README.md +309 -0
- package/src/firestore/utils/pagination.helper/README.md +298 -0
- package/src/firestore/utils/path-resolver/README.md +277 -0
- package/src/firestore/utils/query-builder/README.md +291 -0
- package/src/firestore/utils/quota-error-detector/README.md +355 -0
- package/src/infrastructure/README.md +408 -0
- package/src/infrastructure/config/README.md +262 -0
- package/src/presentation/README.md +556 -0
- package/src/storage/README.md +493 -0
- package/src/storage/deleter/README.md +370 -0
- package/src/storage/types/README.md +313 -0
- package/src/storage/uploader/README.md +409 -0
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
# Firestore Module
|
|
2
|
+
|
|
3
|
+
Comprehensive Firestore database module providing repository pattern, query builders, pagination, quota management, and middleware support for React Native applications.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides a clean, maintainable abstraction over Firestore with repository pattern, quota tracking, query optimization, and comprehensive error handling.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using This Module
|
|
12
|
+
|
|
13
|
+
1. **READ** this entire README
|
|
14
|
+
2. **UNDERSTAND** the repository pattern (not direct Firestore access)
|
|
15
|
+
3. **FOLLOW** existing patterns - don't reinvent
|
|
16
|
+
4. **CHECK** file size limits (max 200 lines per file)
|
|
17
|
+
5. **RESPECT** architectural boundaries
|
|
18
|
+
|
|
19
|
+
### Layer Rules
|
|
20
|
+
|
|
21
|
+
**Domain Layer (`domain/`)**
|
|
22
|
+
- Contains business logic, entities, errors, constants
|
|
23
|
+
- No external dependencies (Firestore-free)
|
|
24
|
+
- Defines interfaces and types
|
|
25
|
+
|
|
26
|
+
**Infrastructure Layer (`infrastructure/`)**
|
|
27
|
+
- Contains repositories, middleware, services
|
|
28
|
+
- Depends on Firestore SDK
|
|
29
|
+
- Implements interfaces defined in domain
|
|
30
|
+
|
|
31
|
+
**Utils Layer (`utils/`)**
|
|
32
|
+
- Contains helper functions and utilities
|
|
33
|
+
- No business logic
|
|
34
|
+
- Reusable across modules
|
|
35
|
+
|
|
36
|
+
## ✅ Required Practices
|
|
37
|
+
|
|
38
|
+
### Repository Pattern Usage
|
|
39
|
+
|
|
40
|
+
1. **Always extend** repository base classes
|
|
41
|
+
2. **Never access** Firestore SDK directly in UI
|
|
42
|
+
3. **Use repositories** for all data operations
|
|
43
|
+
4. **Implement buildQuery()** in query repositories
|
|
44
|
+
5. **Handle errors** appropriately
|
|
45
|
+
|
|
46
|
+
### Query Building
|
|
47
|
+
|
|
48
|
+
1. **Use query builder** for complex queries
|
|
49
|
+
2. **Respect Firestore limitations** (compound queries, IN operator limits)
|
|
50
|
+
3. **Use pagination** for large datasets
|
|
51
|
+
4. **Create indexes** in Firebase Console when needed
|
|
52
|
+
5. **Filter on server** not client-side
|
|
53
|
+
|
|
54
|
+
### Quota Management
|
|
55
|
+
|
|
56
|
+
1. **Track quota usage** with middleware
|
|
57
|
+
2. **Handle quota errors** gracefully
|
|
58
|
+
3. **Implement caching** to reduce quota usage
|
|
59
|
+
4. **Monitor quota metrics** in production
|
|
60
|
+
5. **Inform users** when quota exceeded
|
|
61
|
+
|
|
62
|
+
### Error Handling
|
|
63
|
+
|
|
64
|
+
1. **Use domain-specific errors** (FirebaseFirestoreError)
|
|
65
|
+
2. **Check error types** before handling
|
|
66
|
+
3. **Implement retry logic** for retryable errors
|
|
67
|
+
4. **Stop operations** for quota errors
|
|
68
|
+
5. **Log errors** appropriately
|
|
69
|
+
|
|
70
|
+
## 🚫 Forbidden Practices
|
|
71
|
+
|
|
72
|
+
### ❌ NEVER
|
|
73
|
+
|
|
74
|
+
- Access Firestore SDK directly in UI components
|
|
75
|
+
- Bypass repositories to access Firestore
|
|
76
|
+
- Create circular dependencies between modules
|
|
77
|
+
- Put business logic in UI components
|
|
78
|
+
- Use offset-based pagination (not scalable)
|
|
79
|
+
- Ignore quota tracking
|
|
80
|
+
- Hardcode collection paths
|
|
81
|
+
- Mix architectural layers
|
|
82
|
+
|
|
83
|
+
### ⚠️ Avoid
|
|
84
|
+
|
|
85
|
+
- Large queries without pagination
|
|
86
|
+
- Client-side filtering (use server queries)
|
|
87
|
+
- Not handling quota errors
|
|
88
|
+
- Skipping error handling
|
|
89
|
+
- Complex queries without indexes
|
|
90
|
+
- Duplicate queries (use deduplication middleware)
|
|
91
|
+
|
|
92
|
+
## 🏗️ Architecture
|
|
93
|
+
|
|
94
|
+
**Directory Structure:**
|
|
95
|
+
|
|
96
|
+
**domain/** - Business logic (Firestore-free)
|
|
97
|
+
- entities/ - Domain entities (RequestLog, QuotaMetrics)
|
|
98
|
+
- errors/ - Domain errors (FirebaseFirestoreError)
|
|
99
|
+
- constants/ - Constants (FREE_TIER_LIMITS, QUOTA_THRESHOLDS)
|
|
100
|
+
|
|
101
|
+
**infrastructure/** - Implementation (Firestore-dependent)
|
|
102
|
+
- repositories/ - Repository implementations (Base, Query, Paginated)
|
|
103
|
+
- middleware/ - Middleware (quota tracking, query deduplication)
|
|
104
|
+
- services/ - Services (request logger)
|
|
105
|
+
- config/ - Firestore initialization
|
|
106
|
+
|
|
107
|
+
**utils/** - Helper functions
|
|
108
|
+
- query-builder/ - Query building utilities
|
|
109
|
+
- pagination.helper/ - Pagination logic
|
|
110
|
+
- dateUtils/ - Date conversions
|
|
111
|
+
- path-resolver/ - Path resolution
|
|
112
|
+
- document-mapper.helper/ - Document transformation
|
|
113
|
+
- quota-error-detector/ - Error detection
|
|
114
|
+
|
|
115
|
+
## 🎯 Usage Strategies
|
|
116
|
+
|
|
117
|
+
### For Data Access
|
|
118
|
+
|
|
119
|
+
**Strategy:** Always use repositories, never access Firestore directly.
|
|
120
|
+
|
|
121
|
+
**Repository Selection:**
|
|
122
|
+
- **BaseRepository** - Simple CRUD operations
|
|
123
|
+
- **BaseQueryRepository** - Queries with filtering and sorting
|
|
124
|
+
- **BasePaginatedRepository** - Large datasets requiring pagination
|
|
125
|
+
|
|
126
|
+
**Approach:**
|
|
127
|
+
1. Create repository class extending appropriate base
|
|
128
|
+
2. Implement buildQuery() for query/paginated repositories
|
|
129
|
+
3. Use repository instance in UI or services
|
|
130
|
+
4. Handle errors appropriately
|
|
131
|
+
|
|
132
|
+
### For Pagination
|
|
133
|
+
|
|
134
|
+
**Strategy:** Use cursor-based pagination for scalability.
|
|
135
|
+
|
|
136
|
+
**When to Use:**
|
|
137
|
+
- Infinite scroll implementations
|
|
138
|
+
- Large datasets (>100 documents)
|
|
139
|
+
- Ordered result sets
|
|
140
|
+
- Mobile applications
|
|
141
|
+
|
|
142
|
+
**Approach:**
|
|
143
|
+
1. Extend BasePaginatedRepository
|
|
144
|
+
2. Implement buildQuery with cursor support
|
|
145
|
+
3. Use PaginatedResult type
|
|
146
|
+
4. Store cursor for next page in UI state
|
|
147
|
+
|
|
148
|
+
**Why Cursor-Based:**
|
|
149
|
+
- Scalable (doesn't skip documents)
|
|
150
|
+
- Consistent results
|
|
151
|
+
- Performance (doesn't scan skipped documents)
|
|
152
|
+
- Real-time friendly
|
|
153
|
+
|
|
154
|
+
### For Quota Management
|
|
155
|
+
|
|
156
|
+
**Strategy:** Track quota usage proactively and handle limits gracefully.
|
|
157
|
+
|
|
158
|
+
**When to Use:**
|
|
159
|
+
- All repository operations
|
|
160
|
+
- Production applications
|
|
161
|
+
- Free tier usage
|
|
162
|
+
- High-volume applications
|
|
163
|
+
|
|
164
|
+
**Approach:**
|
|
165
|
+
1. Register quotaTrackingMiddleware in repositories
|
|
166
|
+
2. Monitor metrics with quotaTrackingMiddleware.getMetrics()
|
|
167
|
+
3. Implement warning thresholds (80% of limit)
|
|
168
|
+
4. Handle quota errors with isQuotaError()
|
|
169
|
+
5. Inform users when quota exceeded
|
|
170
|
+
|
|
171
|
+
### For Query Optimization
|
|
172
|
+
|
|
173
|
+
**Strategy:** Build efficient queries that minimize quota usage.
|
|
174
|
+
|
|
175
|
+
**When to Use:**
|
|
176
|
+
- All query operations
|
|
177
|
+
- Large collections
|
|
178
|
+
- Complex filtering
|
|
179
|
+
|
|
180
|
+
**Approach:**
|
|
181
|
+
1. Use query builder for complex queries
|
|
182
|
+
2. Filter on server with where clauses
|
|
183
|
+
3. Use limit to control result size
|
|
184
|
+
4. Create composite indexes in Firebase Console
|
|
185
|
+
5. Use query deduplication middleware
|
|
186
|
+
|
|
187
|
+
## 🔧 Repository Types
|
|
188
|
+
|
|
189
|
+
### BaseRepository
|
|
190
|
+
|
|
191
|
+
**Purpose:** Basic CRUD operations for simple collections.
|
|
192
|
+
|
|
193
|
+
**When to Use:**
|
|
194
|
+
- Simple get/create/update/delete operations
|
|
195
|
+
- No complex filtering needed
|
|
196
|
+
- Small datasets
|
|
197
|
+
|
|
198
|
+
**Methods:**
|
|
199
|
+
- `findById(id)` - Get document by ID
|
|
200
|
+
- `create(data)` - Create new document
|
|
201
|
+
- `update(id, data)` - Update document
|
|
202
|
+
- `delete(id)` - Delete document
|
|
203
|
+
- `getAll()` - Get all documents (use with caution)
|
|
204
|
+
- `exists(id)` - Check if document exists
|
|
205
|
+
|
|
206
|
+
### BaseQueryRepository
|
|
207
|
+
|
|
208
|
+
**Purpose:** Advanced queries with filtering, sorting, and limits.
|
|
209
|
+
|
|
210
|
+
**When to Use:**
|
|
211
|
+
- Need to filter documents
|
|
212
|
+
- Need to sort results
|
|
213
|
+
- Need to limit result size
|
|
214
|
+
- Dynamic query building
|
|
215
|
+
|
|
216
|
+
**Methods:**
|
|
217
|
+
- `find(options)` - Query with options
|
|
218
|
+
- `findFirst(options)` - Get first matching document
|
|
219
|
+
- `count(options)` - Count matching documents
|
|
220
|
+
- `buildQuery(options)` - Build Firestore query (implement this)
|
|
221
|
+
|
|
222
|
+
**Required Implementation:**
|
|
223
|
+
- `buildQuery(options)` - Build query from options
|
|
224
|
+
|
|
225
|
+
### BasePaginatedRepository
|
|
226
|
+
|
|
227
|
+
**Purpose:** Cursor-based pagination for large datasets.
|
|
228
|
+
|
|
229
|
+
**When to Use:**
|
|
230
|
+
- Infinite scroll
|
|
231
|
+
- Large datasets (>100 documents)
|
|
232
|
+
- Ordered result sets
|
|
233
|
+
- Mobile applications
|
|
234
|
+
|
|
235
|
+
**Methods:**
|
|
236
|
+
- `paginate(options)` - Get paginated results
|
|
237
|
+
- `buildQuery(options, cursor?)` - Build query with cursor (implement this)
|
|
238
|
+
|
|
239
|
+
**Required Implementation:**
|
|
240
|
+
- `buildQuery(options, cursor?)` - Build query with cursor support
|
|
241
|
+
|
|
242
|
+
**Returns:**
|
|
243
|
+
- `PaginatedResult<T>` with items, hasMore, nextCursor
|
|
244
|
+
|
|
245
|
+
## 🔌 Middleware System
|
|
246
|
+
|
|
247
|
+
### Quota Tracking Middleware
|
|
248
|
+
|
|
249
|
+
**Purpose:** Automatically track quota usage for all operations.
|
|
250
|
+
|
|
251
|
+
**When to Use:**
|
|
252
|
+
- All repositories in production
|
|
253
|
+
- Free tier usage monitoring
|
|
254
|
+
- High-volume applications
|
|
255
|
+
|
|
256
|
+
**Approach:**
|
|
257
|
+
1. Import quotaTrackingMiddleware
|
|
258
|
+
2. Register in repository constructor
|
|
259
|
+
3. Monitor with getMetrics()
|
|
260
|
+
4. Handle threshold warnings
|
|
261
|
+
|
|
262
|
+
### Query Deduplication Middleware
|
|
263
|
+
|
|
264
|
+
**Purpose:** Prevent duplicate queries within time window.
|
|
265
|
+
|
|
266
|
+
**When to Use:**
|
|
267
|
+
- Frequently accessed data
|
|
268
|
+
- Rapid repeated queries
|
|
269
|
+
- Performance optimization
|
|
270
|
+
|
|
271
|
+
**Approach:**
|
|
272
|
+
1. Import queryDeduplicationMiddleware
|
|
273
|
+
2. Register in repository constructor
|
|
274
|
+
3. Duplicate queries return cached results
|
|
275
|
+
4. Configurable time window
|
|
276
|
+
|
|
277
|
+
### Custom Middleware
|
|
278
|
+
|
|
279
|
+
**Purpose:** Add custom logic to query execution.
|
|
280
|
+
|
|
281
|
+
**When to Use:**
|
|
282
|
+
- Logging
|
|
283
|
+
- Caching
|
|
284
|
+
- Error handling
|
|
285
|
+
- Performance monitoring
|
|
286
|
+
|
|
287
|
+
**Approach:**
|
|
288
|
+
1. Implement QueryMiddleware interface
|
|
289
|
+
2. Implement beforeQuery and/or afterQuery
|
|
290
|
+
3. Register in repository
|
|
291
|
+
4. Middleware runs in registration order
|
|
292
|
+
|
|
293
|
+
## 📊 Utilities
|
|
294
|
+
|
|
295
|
+
### Query Builder
|
|
296
|
+
|
|
297
|
+
**Location:** `utils/query-builder/`
|
|
298
|
+
|
|
299
|
+
**Purpose:** Build complex Firestore queries with filtering, sorting, pagination.
|
|
300
|
+
|
|
301
|
+
**When to Use:**
|
|
302
|
+
- Complex filtering requirements
|
|
303
|
+
- Date range queries
|
|
304
|
+
- Pagination with cursor
|
|
305
|
+
- Dynamic query building
|
|
306
|
+
|
|
307
|
+
**Key Features:**
|
|
308
|
+
- Automatic IN operator chunking (10-item limit)
|
|
309
|
+
- Date range filtering
|
|
310
|
+
- Cursor-based pagination
|
|
311
|
+
- Compound query support
|
|
312
|
+
|
|
313
|
+
### Pagination Helper
|
|
314
|
+
|
|
315
|
+
**Location:** `utils/pagination.helper/`
|
|
316
|
+
|
|
317
|
+
**Purpose:** Handle pagination logic and cursor extraction.
|
|
318
|
+
|
|
319
|
+
**When to Use:**
|
|
320
|
+
- Implementing cursor-based pagination
|
|
321
|
+
- Determining if more pages exist
|
|
322
|
+
- Extracting cursors from documents
|
|
323
|
+
|
|
324
|
+
**Key Features:**
|
|
325
|
+
- Type-safe generic implementation
|
|
326
|
+
- hasMore detection
|
|
327
|
+
- Cursor extraction
|
|
328
|
+
- Limit calculation
|
|
329
|
+
|
|
330
|
+
### Date Utilities
|
|
331
|
+
|
|
332
|
+
**Location:** `utils/dateUtils/`
|
|
333
|
+
|
|
334
|
+
**Purpose:** Convert between ISO strings and Firestore Timestamps.
|
|
335
|
+
|
|
336
|
+
**When to Use:**
|
|
337
|
+
- Storing dates in Firestore
|
|
338
|
+
- Reading dates from Firestore
|
|
339
|
+
- Query filters with dates
|
|
340
|
+
|
|
341
|
+
**Key Functions:**
|
|
342
|
+
- `getCurrentISOString()` - Current time
|
|
343
|
+
- `isoToTimestamp()` - ISO to Timestamp
|
|
344
|
+
- `timestampToISO()` - Timestamp to ISO
|
|
345
|
+
- `timestampToDate()` - Timestamp to Date
|
|
346
|
+
|
|
347
|
+
### Path Resolver
|
|
348
|
+
|
|
349
|
+
**Location:** `utils/path-resolver/`
|
|
350
|
+
|
|
351
|
+
**Purpose:** Standardized path resolution following `users/{userId}/{collectionName}` pattern.
|
|
352
|
+
|
|
353
|
+
**When to Use:**
|
|
354
|
+
- Creating user-specific collections
|
|
355
|
+
- Building repository paths
|
|
356
|
+
- Ensuring consistent path structure
|
|
357
|
+
|
|
358
|
+
**Required Pattern:**
|
|
359
|
+
- All user data: `users/{userId}/{collectionName}`
|
|
360
|
+
- Use FirestorePathResolver class
|
|
361
|
+
- Never construct paths manually
|
|
362
|
+
|
|
363
|
+
### Document Mapper
|
|
364
|
+
|
|
365
|
+
**Location:** `utils/document-mapper.helper/`
|
|
366
|
+
|
|
367
|
+
**Purpose:** Transform Firestore documents to domain entities.
|
|
368
|
+
|
|
369
|
+
**When to Use:**
|
|
370
|
+
- Separating document schema from entities
|
|
371
|
+
- Renaming fields (short names in Firestore)
|
|
372
|
+
- Type transformations
|
|
373
|
+
|
|
374
|
+
**Approach:**
|
|
375
|
+
1. Define document interface (Firestore schema)
|
|
376
|
+
2. Define entity interface (application model)
|
|
377
|
+
3. Create mapper with createDocumentMapper()
|
|
378
|
+
4. Use toEntity/toDocument methods
|
|
379
|
+
|
|
380
|
+
### Quota Error Detector
|
|
381
|
+
|
|
382
|
+
**Location:** `utils/quota-error-detector/`
|
|
383
|
+
|
|
384
|
+
**Purpose:** Detect and handle Firestore quota errors.
|
|
385
|
+
|
|
386
|
+
**When to Use:**
|
|
387
|
+
- Error handling in repositories
|
|
388
|
+
- Quota exceeded detection
|
|
389
|
+
- Retryable error detection
|
|
390
|
+
|
|
391
|
+
**Key Functions:**
|
|
392
|
+
- `isQuotaError(error)` - Check if quota error
|
|
393
|
+
- `isRetryableError(error)` - Check if retryable
|
|
394
|
+
- `getQuotaErrorMessage()` - User-friendly message
|
|
395
|
+
|
|
396
|
+
## 🤖 AI Agent Instructions
|
|
397
|
+
|
|
398
|
+
### When Creating Repository
|
|
399
|
+
|
|
400
|
+
1. Extend appropriate base class (Base, Query, or Paginated)
|
|
401
|
+
2. Implement required buildQuery method
|
|
402
|
+
3. Add custom methods as needed
|
|
403
|
+
4. Register middleware if needed
|
|
404
|
+
5. Handle errors appropriately
|
|
405
|
+
6. Keep file under 200 lines
|
|
406
|
+
|
|
407
|
+
### When Adding Query Logic
|
|
408
|
+
|
|
409
|
+
1. Use query builder utility
|
|
410
|
+
2. Respect Firestore limitations
|
|
411
|
+
3. Handle null/undefined options
|
|
412
|
+
4. Create indexes in Firebase Console
|
|
413
|
+
5. Document query requirements
|
|
414
|
+
|
|
415
|
+
### When Implementing Pagination
|
|
416
|
+
|
|
417
|
+
1. Extend BasePaginatedRepository
|
|
418
|
+
2. Implement buildQuery with cursor support
|
|
419
|
+
3. Use PaginationHelper for logic
|
|
420
|
+
4. Return PaginatedResult type
|
|
421
|
+
5. Store cursor in UI state
|
|
422
|
+
|
|
423
|
+
### When Modifying This Module
|
|
424
|
+
|
|
425
|
+
1. Read module-specific README first
|
|
426
|
+
2. Follow architectural patterns
|
|
427
|
+
3. Keep files under 200 lines
|
|
428
|
+
4. Update documentation
|
|
429
|
+
5. Add error handling
|
|
430
|
+
|
|
431
|
+
## 📏 Code Quality Standards
|
|
432
|
+
|
|
433
|
+
### File Size
|
|
434
|
+
|
|
435
|
+
- **Maximum:** 200 lines per file
|
|
436
|
+
- **Strategy:** Split large repositories into smaller modules
|
|
437
|
+
- **Example:** Split repository into base and query-specific files
|
|
438
|
+
|
|
439
|
+
### TypeScript
|
|
440
|
+
|
|
441
|
+
- Use strict mode
|
|
442
|
+
- Define proper types for all methods
|
|
443
|
+
- Export types used by other modules
|
|
444
|
+
- Never use `any` type
|
|
445
|
+
- Use generic type parameters for repositories
|
|
446
|
+
|
|
447
|
+
### Naming Conventions
|
|
448
|
+
|
|
449
|
+
- Files: `kebab-case.ts` (e.g., `user-repository.ts`)
|
|
450
|
+
- Classes: `PascalCase` (e.g., `UserRepository`)
|
|
451
|
+
- Functions/Variables: `camelCase` (e.g., `findById`)
|
|
452
|
+
- Interfaces/Types: `PascalCase` (e.g., `UserEntity`)
|
|
453
|
+
|
|
454
|
+
### Error Handling
|
|
455
|
+
|
|
456
|
+
1. Use FirebaseFirestoreError for Firestore errors
|
|
457
|
+
2. Include error codes for programmatic handling
|
|
458
|
+
3. Provide context in error messages
|
|
459
|
+
4. Never throw primitives
|
|
460
|
+
5. Log errors appropriately
|
|
461
|
+
|
|
462
|
+
## 🚨 Common Mistakes to Avoid
|
|
463
|
+
|
|
464
|
+
1. ❌ Accessing Firestore SDK directly in UI
|
|
465
|
+
- ✅ Use repositories
|
|
466
|
+
|
|
467
|
+
2. ❌ Not implementing pagination for large datasets
|
|
468
|
+
- ✅ Use BasePaginatedRepository
|
|
469
|
+
|
|
470
|
+
3. ❌ Ignoring quota tracking
|
|
471
|
+
- ✅ Register quotaTrackingMiddleware
|
|
472
|
+
|
|
473
|
+
4. ❌ Client-side filtering
|
|
474
|
+
- ✅ Use server-side queries
|
|
475
|
+
|
|
476
|
+
5. ❌ Not handling quota errors
|
|
477
|
+
- ✅ Use isQuotaError() and handle appropriately
|
|
478
|
+
|
|
479
|
+
## 📚 Related Documentation
|
|
480
|
+
|
|
481
|
+
- [Development Guidelines](../../CONTRIBUTING.md)
|
|
482
|
+
- [Repository Documentation](./infrastructure/repositories/README.md)
|
|
483
|
+
- [Middleware Documentation](./infrastructure/middleware/README.md)
|
|
484
|
+
- [Query Builder](./utils/query-builder/README.md)
|
|
485
|
+
- [Pagination Helper](./utils/pagination.helper/README.md)
|
|
486
|
+
- [Path Resolver](./utils/path-resolver/README.md)
|
|
487
|
+
- [Firestore Index Management](https://firebase.google.com/docs/firestore/query-data/indexing)
|
|
488
|
+
|
|
489
|
+
## 🔗 API Reference
|
|
490
|
+
|
|
491
|
+
### Main Exports
|
|
492
|
+
|
|
493
|
+
**Repositories:**
|
|
494
|
+
- `BaseRepository<T>` - Basic CRUD operations
|
|
495
|
+
- `BaseQueryRepository<T, O>` - Query with filtering
|
|
496
|
+
- `BasePaginatedRepository<T, O>` - Pagination support
|
|
497
|
+
|
|
498
|
+
**Middleware:**
|
|
499
|
+
- `quotaTrackingMiddleware` - Track quota usage
|
|
500
|
+
- `queryDeduplicationMiddleware` - Prevent duplicate queries
|
|
501
|
+
|
|
502
|
+
**Utilities:**
|
|
503
|
+
- `buildQuery()` - Build Firestore queries
|
|
504
|
+
- `createDocumentMapper()` - Document transformation
|
|
505
|
+
- `FirestorePathResolver` - Path resolution
|
|
506
|
+
- PaginationHelper - Pagination logic
|
|
507
|
+
- Date utilities - Date/timestamp conversion
|
|
508
|
+
- Quota error detector - Error detection
|
|
509
|
+
|
|
510
|
+
**Services:**
|
|
511
|
+
- `requestLoggerService` - Log Firestore requests
|
|
512
|
+
|
|
513
|
+
**Types:**
|
|
514
|
+
- `PaginatedResult<T>` - Pagination result type
|
|
515
|
+
- `PaginationParams` - Pagination parameters
|
|
516
|
+
- `QuotaMetrics` - Quota usage metrics
|
|
517
|
+
- `FirebaseFirestoreError` - Firestore error class
|
|
518
|
+
|
|
519
|
+
## 🎓 Key Concepts
|
|
520
|
+
|
|
521
|
+
### Repository Pattern
|
|
522
|
+
|
|
523
|
+
**Why Repository Pattern?**
|
|
524
|
+
- Abstracts Firestore implementation details
|
|
525
|
+
- Makes code testable without Firestore
|
|
526
|
+
- Centralizes data access logic
|
|
527
|
+
- Easier to modify or replace data source
|
|
528
|
+
|
|
529
|
+
**How it works:**
|
|
530
|
+
1. Repository defines data operations interface
|
|
531
|
+
2. Base repository provides standard implementations
|
|
532
|
+
3. Custom repositories extend and specialize
|
|
533
|
+
4. UI uses repositories, not Firestore directly
|
|
534
|
+
|
|
535
|
+
### Cursor-Based Pagination
|
|
536
|
+
|
|
537
|
+
**Why Cursor-Based?**
|
|
538
|
+
- Offset-based doesn't scale (scans all skipped documents)
|
|
539
|
+
- Cursor-based starts from specific position
|
|
540
|
+
- Consistent results (no missing/duplicates)
|
|
541
|
+
- Better performance
|
|
542
|
+
|
|
543
|
+
**How it works:**
|
|
544
|
+
1. Fetch limit + 1 documents
|
|
545
|
+
2. If returned > limit, hasMore = true
|
|
546
|
+
3. Use last document as cursor for next page
|
|
547
|
+
4. Pass cursor in subsequent requests
|
|
548
|
+
|
|
549
|
+
### Middleware Pattern
|
|
550
|
+
|
|
551
|
+
**Why Middleware?**
|
|
552
|
+
- Cross-cutting concerns (logging, quota tracking)
|
|
553
|
+
- Separation of concerns
|
|
554
|
+
- Composable behavior
|
|
555
|
+
- Easy to add/remove
|
|
556
|
+
|
|
557
|
+
**How it works:**
|
|
558
|
+
1. Middleware registered in repository
|
|
559
|
+
2. beforeQuery runs before query execution
|
|
560
|
+
3. afterQuery runs after query execution
|
|
561
|
+
4. Multiple middleware chain together
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
|
|
565
|
+
**Last Updated:** 2025-01-08
|
|
566
|
+
**Maintainer:** Firestore Module Team
|