@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,574 @@
|
|
|
1
|
+
# Firestore Utilities
|
|
2
|
+
|
|
3
|
+
Utility functions for Firestore operations including date handling, query building, pagination, document mapping, path resolution, and error detection.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides reusable utility functions for common Firestore operations, ensuring consistency and reducing boilerplate code across the application.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Firestore Utils
|
|
12
|
+
|
|
13
|
+
1. **IMPORT** from `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
14
|
+
2. **USE** utilities instead of writing custom implementations
|
|
15
|
+
3. **FOLLOW** established patterns for consistency
|
|
16
|
+
4. **NEVER** duplicate utility functionality
|
|
17
|
+
5. **CHECK** if utility exists before creating new functions
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Use date utilities** - For all Firestore timestamp conversions
|
|
22
|
+
2. **Use query builder** - For programmatic query construction
|
|
23
|
+
3. **Use pagination helper** - For consistent pagination logic
|
|
24
|
+
4. **Use document mapper** - For type-safe document transformations
|
|
25
|
+
5. **Use path resolver** - For standardized path generation
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Write custom timestamp conversion logic
|
|
32
|
+
- Build queries with string concatenation
|
|
33
|
+
- Implement pagination from scratch
|
|
34
|
+
- Manually map Firestore documents
|
|
35
|
+
- Hardcode collection paths
|
|
36
|
+
- Ignore quota error detection
|
|
37
|
+
|
|
38
|
+
## ⚠️ Avoid
|
|
39
|
+
|
|
40
|
+
- Inconsistent date formats
|
|
41
|
+
- Query string building
|
|
42
|
+
- Duplicate pagination logic
|
|
43
|
+
- Manual document casting
|
|
44
|
+
- scattered path patterns
|
|
45
|
+
- Missing error detection
|
|
46
|
+
|
|
47
|
+
## Date Utilities
|
|
48
|
+
|
|
49
|
+
### isoToTimestamp
|
|
50
|
+
|
|
51
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
52
|
+
|
|
53
|
+
**Purpose:** Convert ISO string to Firestore Timestamp
|
|
54
|
+
|
|
55
|
+
**Parameters:**
|
|
56
|
+
- `isoString: string` - ISO date string
|
|
57
|
+
|
|
58
|
+
**Returns:** Firestore Timestamp object
|
|
59
|
+
|
|
60
|
+
**Usage Strategy:**
|
|
61
|
+
1. Use when querying with timestamps
|
|
62
|
+
2. Convert stored ISO strings to Timestamps
|
|
63
|
+
3. Pass to Firestore where clause
|
|
64
|
+
4. Handle invalid ISO strings
|
|
65
|
+
|
|
66
|
+
**When to Use:**
|
|
67
|
+
- Query filters with timestamps
|
|
68
|
+
- Before Firestore operations
|
|
69
|
+
- Converting stored dates
|
|
70
|
+
- Timestamp comparisons
|
|
71
|
+
|
|
72
|
+
### timestampToISO
|
|
73
|
+
|
|
74
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
75
|
+
|
|
76
|
+
**Purpose:** Convert Firestore Timestamp to ISO string
|
|
77
|
+
|
|
78
|
+
**Parameters:**
|
|
79
|
+
- `timestamp: Timestamp` - Firestore Timestamp object
|
|
80
|
+
|
|
81
|
+
**Returns:** ISO string date
|
|
82
|
+
|
|
83
|
+
**Usage Strategy:**
|
|
84
|
+
1. Convert Firestore timestamps to ISO
|
|
85
|
+
2. Store dates as ISO strings in database
|
|
86
|
+
3. Use for display or calculations
|
|
87
|
+
4. Handle null/undefined timestamps
|
|
88
|
+
|
|
89
|
+
**When to Use:**
|
|
90
|
+
- After fetching documents
|
|
91
|
+
- Storing dates in state
|
|
92
|
+
- Displaying dates to users
|
|
93
|
+
- Date calculations
|
|
94
|
+
|
|
95
|
+
### timestampToDate
|
|
96
|
+
|
|
97
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
98
|
+
|
|
99
|
+
**Purpose:** Convert Firestore Timestamp to JavaScript Date
|
|
100
|
+
|
|
101
|
+
**Parameters:**
|
|
102
|
+
- `timestamp: Timestamp` - Firestore Timestamp object
|
|
103
|
+
|
|
104
|
+
**Returns:** JavaScript Date object
|
|
105
|
+
|
|
106
|
+
**Usage Strategy:**
|
|
107
|
+
1. Convert to Date for date operations
|
|
108
|
+
2. Use for date formatting
|
|
109
|
+
3. Use for date calculations
|
|
110
|
+
4. Handle invalid timestamps
|
|
111
|
+
|
|
112
|
+
**When to Use:**
|
|
113
|
+
- Date formatting with toLocaleDateString
|
|
114
|
+
- Date calculations (add days, etc.)
|
|
115
|
+
- Date comparisons
|
|
116
|
+
- Display formatting
|
|
117
|
+
|
|
118
|
+
### getCurrentISOString
|
|
119
|
+
|
|
120
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
121
|
+
|
|
122
|
+
**Purpose:** Get current date/time as ISO string
|
|
123
|
+
|
|
124
|
+
**Parameters:** None
|
|
125
|
+
|
|
126
|
+
**Returns:** Current ISO string
|
|
127
|
+
|
|
128
|
+
**Usage Strategy:**
|
|
129
|
+
1. Use for createdAt timestamps
|
|
130
|
+
2. Use for updatedAt timestamps
|
|
131
|
+
3. Call once per document creation
|
|
132
|
+
4. Consistent timestamp format
|
|
133
|
+
|
|
134
|
+
**When to Use:**
|
|
135
|
+
- Creating new documents
|
|
136
|
+
- Updating documents
|
|
137
|
+
- Timestamp generation
|
|
138
|
+
- Audit trails
|
|
139
|
+
|
|
140
|
+
## Query Builder
|
|
141
|
+
|
|
142
|
+
### buildQuery
|
|
143
|
+
|
|
144
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
145
|
+
|
|
146
|
+
**Purpose:** Build Firestore queries with filters and sorting
|
|
147
|
+
|
|
148
|
+
**Parameters:**
|
|
149
|
+
- `collection: CollectionReference` - Base collection
|
|
150
|
+
- `options: QueryOptions` - Query configuration
|
|
151
|
+
|
|
152
|
+
**QueryOptions Properties:**
|
|
153
|
+
- `filters?: Filter[]` - Array of query filters
|
|
154
|
+
- `orderBy?: { field: string; direction?: 'asc' | 'desc' }`
|
|
155
|
+
- `limit?: number` - Max documents to return
|
|
156
|
+
|
|
157
|
+
**Returns:** Firestore Query object
|
|
158
|
+
|
|
159
|
+
**Usage Strategy:**
|
|
160
|
+
1. Import buildQuery from utils
|
|
161
|
+
2. Create filters with createEqualFilter or createInFilter
|
|
162
|
+
3. Pass collection and options
|
|
163
|
+
4. Execute returned query
|
|
164
|
+
5. Handle query results
|
|
165
|
+
|
|
166
|
+
**When to Use:**
|
|
167
|
+
- Dynamic queries based on user input
|
|
168
|
+
- Complex filtering requirements
|
|
169
|
+
- Ordered result sets
|
|
170
|
+
- Limited result sets
|
|
171
|
+
|
|
172
|
+
### createEqualFilter
|
|
173
|
+
|
|
174
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
175
|
+
|
|
176
|
+
**Purpose:** Create equality filter for queries
|
|
177
|
+
|
|
178
|
+
**Parameters:**
|
|
179
|
+
- `field: string` - Field name
|
|
180
|
+
- `value: any` - Value to compare
|
|
181
|
+
|
|
182
|
+
**Returns:** Filter object
|
|
183
|
+
|
|
184
|
+
**Usage Strategy:**
|
|
185
|
+
1. Use for exact match queries
|
|
186
|
+
2. Chain multiple filters
|
|
187
|
+
3. Use with buildQuery
|
|
188
|
+
4. Type-safe field names
|
|
189
|
+
|
|
190
|
+
**When to Use:**
|
|
191
|
+
- Finding specific documents
|
|
192
|
+
- User ID lookups
|
|
193
|
+
- Category filtering
|
|
194
|
+
- Status filtering
|
|
195
|
+
|
|
196
|
+
### createInFilter
|
|
197
|
+
|
|
198
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
199
|
+
|
|
200
|
+
**Purpose:** Create IN filter for multiple values
|
|
201
|
+
|
|
202
|
+
**Parameters:**
|
|
203
|
+
- `field: string` - Field name
|
|
204
|
+
- `values: any[]` - Array of values
|
|
205
|
+
|
|
206
|
+
**Returns:** Filter object
|
|
207
|
+
|
|
208
|
+
**Usage Strategy:**
|
|
209
|
+
1. Use for multiple value matching
|
|
210
|
+
2. Limit to 10 values (Firestore limit)
|
|
211
|
+
3. Use with buildQuery
|
|
212
|
+
4. Consider array-contains for array fields
|
|
213
|
+
|
|
214
|
+
**When to Use:**
|
|
215
|
+
- Multiple category selection
|
|
216
|
+
- Multi-status queries
|
|
217
|
+
- Batch ID lookups
|
|
218
|
+
- Multiple user queries
|
|
219
|
+
|
|
220
|
+
## Pagination Helper
|
|
221
|
+
|
|
222
|
+
### createPaginationHelper
|
|
223
|
+
|
|
224
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
225
|
+
|
|
226
|
+
**Purpose:** Create helper for cursor-based pagination
|
|
227
|
+
|
|
228
|
+
**Parameters:**
|
|
229
|
+
- `getCursor: (doc) => string` - Extract cursor from document
|
|
230
|
+
|
|
231
|
+
**Returns:** Pagination helper object with methods
|
|
232
|
+
|
|
233
|
+
**Methods:**
|
|
234
|
+
- `buildResult(items, limit)` - Build PaginatedResult from items
|
|
235
|
+
- `getCursor(doc)` - Extract cursor from document
|
|
236
|
+
|
|
237
|
+
**Usage Strategy:**
|
|
238
|
+
1. Create helper for each collection
|
|
239
|
+
2. Define cursor extraction function
|
|
240
|
+
3. Fetch limit + 1 documents
|
|
241
|
+
4. Use buildResult to create PaginatedResult
|
|
242
|
+
5. Store nextCursor for subsequent requests
|
|
243
|
+
|
|
244
|
+
**When to Use:**
|
|
245
|
+
- Large datasets requiring pagination
|
|
246
|
+
- Infinite scroll implementations
|
|
247
|
+
- Performance optimization
|
|
248
|
+
- Mobile applications
|
|
249
|
+
|
|
250
|
+
**Cursor Strategy:**
|
|
251
|
+
- Use sortable field for cursor (createdAt, document ID)
|
|
252
|
+
- Extract field value as cursor string
|
|
253
|
+
- Pass cursor to next page query
|
|
254
|
+
- Consistent sorting required
|
|
255
|
+
|
|
256
|
+
## Document Mapper
|
|
257
|
+
|
|
258
|
+
### createDocumentMapper
|
|
259
|
+
|
|
260
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
261
|
+
|
|
262
|
+
**Purpose:** Create type-safe document mapper for Firestore documents
|
|
263
|
+
|
|
264
|
+
**Parameters:**
|
|
265
|
+
- `transform: (doc) => T` - Transformation function
|
|
266
|
+
|
|
267
|
+
**Returns:** Mapper function for documents
|
|
268
|
+
|
|
269
|
+
**Usage Strategy:**
|
|
270
|
+
1. Define entity type
|
|
271
|
+
2. Create transformation function
|
|
272
|
+
3. Add createdAt, updatedAt, id fields
|
|
273
|
+
4. Type-safe document mapping
|
|
274
|
+
5. Use in repository methods
|
|
275
|
+
|
|
276
|
+
**When to Use:**
|
|
277
|
+
- Repository implementations
|
|
278
|
+
- Type safety requirements
|
|
279
|
+
- Consistent document structure
|
|
280
|
+
- Adding metadata to documents
|
|
281
|
+
|
|
282
|
+
**Document Enrichment:**
|
|
283
|
+
- Add document id to entity
|
|
284
|
+
- Add timestamps (createdAt, updatedAt)
|
|
285
|
+
- Transform field names if needed
|
|
286
|
+
- Validate data structure
|
|
287
|
+
- Convert nested objects
|
|
288
|
+
|
|
289
|
+
## Path Resolver
|
|
290
|
+
|
|
291
|
+
### FirestorePathResolver
|
|
292
|
+
|
|
293
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
294
|
+
|
|
295
|
+
**Purpose:** Generate standardized Firestore collection paths
|
|
296
|
+
|
|
297
|
+
**Constructor:**
|
|
298
|
+
- `collectionName: string` - Collection name
|
|
299
|
+
|
|
300
|
+
**Methods:**
|
|
301
|
+
- `getUserCollection(userId)` - Get user's collection reference
|
|
302
|
+
- `getDocRef(userId, docId)` - Get document reference
|
|
303
|
+
|
|
304
|
+
**Usage Strategy:**
|
|
305
|
+
1. Create resolver instance per collection
|
|
306
|
+
2. Pass collection name to constructor
|
|
307
|
+
3. Use getUserCollection for queries
|
|
308
|
+
4. Use getDocRef for document operations
|
|
309
|
+
5. Follow users/{userId}/{collectionName} pattern
|
|
310
|
+
|
|
311
|
+
**When to Use:**
|
|
312
|
+
- Repository implementations
|
|
313
|
+
- User-specific data
|
|
314
|
+
- Standardized paths
|
|
315
|
+
- Security rules compatibility
|
|
316
|
+
|
|
317
|
+
**Path Pattern:**
|
|
318
|
+
- Collection: `users/{userId}/{collectionName}`
|
|
319
|
+
- Document: `users/{userId}/{collectionName}/{docId}`
|
|
320
|
+
- Consistent across application
|
|
321
|
+
- Security rules friendly
|
|
322
|
+
- Multi-tenant support
|
|
323
|
+
|
|
324
|
+
## Quota Error Detector
|
|
325
|
+
|
|
326
|
+
### isQuotaError
|
|
327
|
+
|
|
328
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
329
|
+
|
|
330
|
+
**Purpose:** Check if error is Firestore quota error
|
|
331
|
+
|
|
332
|
+
**Parameters:**
|
|
333
|
+
- `error: unknown` - Error to check
|
|
334
|
+
|
|
335
|
+
**Returns:** `boolean` - True if quota error
|
|
336
|
+
|
|
337
|
+
**Usage Strategy:**
|
|
338
|
+
1. Wrap Firestore operations in try-catch
|
|
339
|
+
2. Check error with isQuotaError()
|
|
340
|
+
3. Show user-friendly message
|
|
341
|
+
4. Disable further operations
|
|
342
|
+
5. Never retry quota errors
|
|
343
|
+
|
|
344
|
+
**When to Use:**
|
|
345
|
+
- After Firestore operations
|
|
346
|
+
- Error handling logic
|
|
347
|
+
- User feedback
|
|
348
|
+
- Operation throttling
|
|
349
|
+
|
|
350
|
+
### isRetryableError
|
|
351
|
+
|
|
352
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
353
|
+
|
|
354
|
+
**Purpose:** Check if error is retryable
|
|
355
|
+
|
|
356
|
+
**Parameters:**
|
|
357
|
+
- `error: unknown` - Error to check
|
|
358
|
+
|
|
359
|
+
**Returns:** `boolean` - True if retryable
|
|
360
|
+
|
|
361
|
+
**Usage Strategy:**
|
|
362
|
+
1. Check error after failed operation
|
|
363
|
+
2. Retry with exponential backoff if true
|
|
364
|
+
3. Set max retry limit (typically 3)
|
|
365
|
+
4. Don't retry quota errors
|
|
366
|
+
5. Log retryable errors
|
|
367
|
+
|
|
368
|
+
**When to Use:**
|
|
369
|
+
- Transient error handling
|
|
370
|
+
- Network failures
|
|
371
|
+
- Resource exhaustion
|
|
372
|
+
- Rate limit handling
|
|
373
|
+
|
|
374
|
+
### getQuotaErrorMessage
|
|
375
|
+
|
|
376
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
377
|
+
|
|
378
|
+
**Purpose:** Get user-friendly quota error message
|
|
379
|
+
|
|
380
|
+
**Parameters:** None
|
|
381
|
+
|
|
382
|
+
**Returns:** `string` - Error message
|
|
383
|
+
|
|
384
|
+
**Usage Strategy:**
|
|
385
|
+
1. Call when quota error detected
|
|
386
|
+
2. Show message to user
|
|
387
|
+
3. Suggest upgrade or retry later
|
|
388
|
+
4. Localize message if needed
|
|
389
|
+
5. Provide actionable guidance
|
|
390
|
+
|
|
391
|
+
**When to Use:**
|
|
392
|
+
- UI error display
|
|
393
|
+
- User notifications
|
|
394
|
+
- Error logging
|
|
395
|
+
- Support messages
|
|
396
|
+
|
|
397
|
+
## Common Mistakes to Avoid
|
|
398
|
+
|
|
399
|
+
1. ❌ Writing custom date conversion logic
|
|
400
|
+
- ✅ Use provided date utilities
|
|
401
|
+
|
|
402
|
+
2. ❌ Building queries with string concatenation
|
|
403
|
+
- ✅ Use query builder utilities
|
|
404
|
+
|
|
405
|
+
3. ❌ Manual pagination implementation
|
|
406
|
+
- ✅ Use pagination helper
|
|
407
|
+
|
|
408
|
+
4. ❌ Hardcoding collection paths
|
|
409
|
+
- ✅ Use path resolver
|
|
410
|
+
|
|
411
|
+
5. ❌ Not detecting quota errors
|
|
412
|
+
- ✅ Use quota error detector
|
|
413
|
+
|
|
414
|
+
## AI Agent Instructions
|
|
415
|
+
|
|
416
|
+
### When Using Date Utilities
|
|
417
|
+
|
|
418
|
+
1. Always use ISO strings for storage
|
|
419
|
+
2. Convert to Timestamp for queries
|
|
420
|
+
3. Convert to Date for display
|
|
421
|
+
4. Use getCurrentISOString for timestamps
|
|
422
|
+
5. Handle invalid date formats
|
|
423
|
+
|
|
424
|
+
### When Building Queries
|
|
425
|
+
|
|
426
|
+
1. Use buildQuery for complex queries
|
|
427
|
+
2. Create filters with filter utilities
|
|
428
|
+
3. Specify orderBy for sorted results
|
|
429
|
+
4. Set limit for result size
|
|
430
|
+
5. Handle empty results gracefully
|
|
431
|
+
|
|
432
|
+
### When Implementing Pagination
|
|
433
|
+
|
|
434
|
+
1. Use createPaginationHelper
|
|
435
|
+
2. Define cursor extraction function
|
|
436
|
+
3. Fetch limit + 1 documents
|
|
437
|
+
4. Use buildResult for PaginatedResult
|
|
438
|
+
5. Store nextCursor for subsequent requests
|
|
439
|
+
|
|
440
|
+
### When Mapping Documents
|
|
441
|
+
|
|
442
|
+
1. Use createDocumentMapper
|
|
443
|
+
2. Add metadata (id, timestamps)
|
|
444
|
+
3. Transform field names if needed
|
|
445
|
+
4. Ensure type safety
|
|
446
|
+
5. Validate data structure
|
|
447
|
+
|
|
448
|
+
## Code Quality Standards
|
|
449
|
+
|
|
450
|
+
### Utility Usage
|
|
451
|
+
|
|
452
|
+
- Import from correct path
|
|
453
|
+
- Use utilities consistently
|
|
454
|
+
- Don't duplicate functionality
|
|
455
|
+
- Handle errors appropriately
|
|
456
|
+
- Type-safe operations
|
|
457
|
+
|
|
458
|
+
### Error Handling
|
|
459
|
+
|
|
460
|
+
- Check for quota errors
|
|
461
|
+
- Retry retryable errors
|
|
462
|
+
- Show user-friendly messages
|
|
463
|
+
- Log errors appropriately
|
|
464
|
+
- Handle edge cases
|
|
465
|
+
|
|
466
|
+
### Performance
|
|
467
|
+
|
|
468
|
+
- Use pagination for large datasets
|
|
469
|
+
- Limit query results
|
|
470
|
+
- Use indexes for queried fields
|
|
471
|
+
- Avoid client-side filtering
|
|
472
|
+
- Batch operations when possible
|
|
473
|
+
|
|
474
|
+
## Performance Considerations
|
|
475
|
+
|
|
476
|
+
### Date Operations
|
|
477
|
+
|
|
478
|
+
- ISO strings for storage (efficient)
|
|
479
|
+
- Timestamp for queries (indexed)
|
|
480
|
+
- Date for display (formatting)
|
|
481
|
+
- Convert once, reuse results
|
|
482
|
+
- Cache conversions when appropriate
|
|
483
|
+
|
|
484
|
+
### Query Building
|
|
485
|
+
|
|
486
|
+
- Build queries programmatically
|
|
487
|
+
- Use compound indexes
|
|
488
|
+
- Limit result size
|
|
489
|
+
- Filter on server-side
|
|
490
|
+
- Avoid unnecessary sorts
|
|
491
|
+
|
|
492
|
+
### Pagination
|
|
493
|
+
|
|
494
|
+
- Fetch limit + 1 for hasMore detection
|
|
495
|
+
- Use cursor-based pagination
|
|
496
|
+
- Store only cursor in state
|
|
497
|
+
- Load next page on demand
|
|
498
|
+
- Stop when hasMore is false
|
|
499
|
+
|
|
500
|
+
## Related Documentation
|
|
501
|
+
|
|
502
|
+
- [Date Utils README](../dateUtils/README.md)
|
|
503
|
+
- [Query Builder README](../query-builder/README.md)
|
|
504
|
+
- [Pagination Helper README](../pagination.helper/README.md)
|
|
505
|
+
- [Document Mapper README](../document-mapper.helper/README.md)
|
|
506
|
+
- [Path Resolver README](../path-resolver/README.md)
|
|
507
|
+
- [Quota Error Detector README](../quota-error-detector/README.md)
|
|
508
|
+
|
|
509
|
+
## API Reference
|
|
510
|
+
|
|
511
|
+
### Date Utilities
|
|
512
|
+
|
|
513
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
514
|
+
|
|
515
|
+
| Function | Parameters | Returns | Description |
|
|
516
|
+
|----------|------------|---------|-------------|
|
|
517
|
+
| `isoToTimestamp` | `isoString` | `Timestamp` | Convert ISO to Timestamp |
|
|
518
|
+
| `timestampToISO` | `timestamp` | `string` | Convert Timestamp to ISO |
|
|
519
|
+
| `timestampToDate` | `timestamp` | `Date` | Convert Timestamp to Date |
|
|
520
|
+
| `getCurrentISOString` | - | `string` | Get current ISO string |
|
|
521
|
+
|
|
522
|
+
### Query Builder
|
|
523
|
+
|
|
524
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
525
|
+
|
|
526
|
+
| Function | Parameters | Returns | Description |
|
|
527
|
+
|----------|------------|---------|-------------|
|
|
528
|
+
| `buildQuery` | `collection, options` | `Query` | Build Firestore query |
|
|
529
|
+
| `createEqualFilter` | `field, value` | `Filter` | Create equality filter |
|
|
530
|
+
| `createInFilter` | `field, values[]` | `Filter` | Create IN filter |
|
|
531
|
+
|
|
532
|
+
### Pagination Helper
|
|
533
|
+
|
|
534
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
535
|
+
|
|
536
|
+
| Function | Parameters | Returns | Description |
|
|
537
|
+
|----------|------------|---------|-------------|
|
|
538
|
+
| `createPaginationHelper` | `getCursor(doc)` | `PaginationHelper` | Create pagination helper |
|
|
539
|
+
|
|
540
|
+
**PaginationHelper Methods:**
|
|
541
|
+
- `buildResult(items, limit)` - Build PaginatedResult
|
|
542
|
+
- `getCursor(doc)` - Extract cursor from document
|
|
543
|
+
|
|
544
|
+
### Document Mapper
|
|
545
|
+
|
|
546
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
547
|
+
|
|
548
|
+
| Function | Parameters | Returns | Description |
|
|
549
|
+
|----------|------------|---------|-------------|
|
|
550
|
+
| `createDocumentMapper` | `transform(doc)` | `Mapper` | Create document mapper |
|
|
551
|
+
|
|
552
|
+
### Path Resolver
|
|
553
|
+
|
|
554
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
555
|
+
|
|
556
|
+
| Class | Methods | Description |
|
|
557
|
+
|------|---------|-------------|
|
|
558
|
+
| `FirestorePathResolver` | `getUserCollection(userId)` | Get user collection reference |
|
|
559
|
+
| `FirestorePathResolver` | `getDocRef(userId, docId)` | Get document reference |
|
|
560
|
+
|
|
561
|
+
### Quota Error Detector
|
|
562
|
+
|
|
563
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/utils`
|
|
564
|
+
|
|
565
|
+
| Function | Parameters | Returns | Description |
|
|
566
|
+
|----------|------------|---------|-------------|
|
|
567
|
+
| `isQuotaError` | `error` | `boolean` | Check if quota error |
|
|
568
|
+
| `isRetryableError` | `error` | `boolean` | Check if retryable |
|
|
569
|
+
| `getQuotaErrorMessage` | - | `string` | Get error message |
|
|
570
|
+
|
|
571
|
+
---
|
|
572
|
+
|
|
573
|
+
**Last Updated:** 2025-01-08
|
|
574
|
+
**Maintainer:** Firestore Module Team
|