@umituz/react-native-firebase 1.13.58 → 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,286 @@
|
|
|
1
|
+
# Request Log Types
|
|
2
|
+
|
|
3
|
+
TypeScript types for Firestore request logging and tracking.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides type definitions for logging Firestore requests including request types, logs, and statistics. Used for monitoring, analytics, and quota tracking.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Request Log Types
|
|
12
|
+
|
|
13
|
+
1. **USE** types for type-safe request logging
|
|
14
|
+
2. **LOG** all Firestore operations for monitoring
|
|
15
|
+
3. **TRACK** quota usage with request logs
|
|
16
|
+
4. **ANALYZE** logs for performance optimization
|
|
17
|
+
5. **NEVER** log sensitive user data in requests
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Log all Firestore operations** with RequestLog
|
|
22
|
+
2. **Use RequestType** for operation categorization
|
|
23
|
+
3. **Calculate statistics** with RequestStats
|
|
24
|
+
4. **Import types from correct path**
|
|
25
|
+
5. **Use queryHash for duplicate detection**
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Log sensitive user data in request logs
|
|
32
|
+
- Log request payloads or document content
|
|
33
|
+
- Ignore logging for Firestore operations
|
|
34
|
+
- Use request logs for debugging only (also for analytics)
|
|
35
|
+
- Store logs indefinitely (cleanup old logs)
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Logging every single read operation (use sampling)
|
|
40
|
+
- Not cleaning up old logs
|
|
41
|
+
- Logging in production without monitoring
|
|
42
|
+
- Storing logs in production database
|
|
43
|
+
- Complex logging logic in critical path
|
|
44
|
+
|
|
45
|
+
## Usage Strategies
|
|
46
|
+
|
|
47
|
+
### For Request Logging
|
|
48
|
+
|
|
49
|
+
**Strategy:** Log every Firestore operation for monitoring and quota tracking.
|
|
50
|
+
|
|
51
|
+
**Import From:** `src/firestore/domain/entities`
|
|
52
|
+
|
|
53
|
+
**When to Use:**
|
|
54
|
+
- Repository operations (read, write, delete)
|
|
55
|
+
- Quota tracking middleware
|
|
56
|
+
- Performance monitoring
|
|
57
|
+
- Analytics and reporting
|
|
58
|
+
|
|
59
|
+
**Logging Strategy:**
|
|
60
|
+
1. Create RequestLog before operation
|
|
61
|
+
2. Set operation type (read/write/delete)
|
|
62
|
+
3. Record collection name
|
|
63
|
+
4. Count affected documents
|
|
64
|
+
5. Add timestamp and query hash
|
|
65
|
+
6. Log operation completion
|
|
66
|
+
|
|
67
|
+
### For Quota Tracking
|
|
68
|
+
|
|
69
|
+
**Strategy:** Use request logs to track Firestore quota usage.
|
|
70
|
+
|
|
71
|
+
**Import From:** `src/firestore/domain/entities`
|
|
72
|
+
|
|
73
|
+
**When to Use:**
|
|
74
|
+
- Monitoring quota consumption
|
|
75
|
+
- Warning threshold detection
|
|
76
|
+
- Usage analytics
|
|
77
|
+
- Cost optimization
|
|
78
|
+
|
|
79
|
+
**Tracking Metrics:**
|
|
80
|
+
- Total read operations
|
|
81
|
+
- Total write operations
|
|
82
|
+
- Total delete operations
|
|
83
|
+
- Average document count per request
|
|
84
|
+
- Request rate over time
|
|
85
|
+
|
|
86
|
+
### For Analytics
|
|
87
|
+
|
|
88
|
+
**Strategy:** Analyze request logs for performance insights.
|
|
89
|
+
|
|
90
|
+
**Import From:** `src/firestore/domain/entities`
|
|
91
|
+
|
|
92
|
+
**When to Use:**
|
|
93
|
+
- Performance monitoring
|
|
94
|
+
- Query optimization
|
|
95
|
+
- Usage patterns analysis
|
|
96
|
+
- Cost optimization
|
|
97
|
+
|
|
98
|
+
**Analytics Metrics:**
|
|
99
|
+
- Most queried collections
|
|
100
|
+
- Average document counts
|
|
101
|
+
- Request frequency
|
|
102
|
+
- Query patterns (via queryHash)
|
|
103
|
+
|
|
104
|
+
## Type Definitions
|
|
105
|
+
|
|
106
|
+
### RequestLog
|
|
107
|
+
|
|
108
|
+
**Import From:** `src/firestore/domain/entities`
|
|
109
|
+
|
|
110
|
+
**Purpose:** Log entry for a Firestore request
|
|
111
|
+
|
|
112
|
+
**Properties:**
|
|
113
|
+
- `type: RequestType` - Type of operation (read/write/delete)
|
|
114
|
+
- `collectionName: string` - Collection being accessed
|
|
115
|
+
- `documentCount: number` - Number of documents affected
|
|
116
|
+
- `timestamp: number` - Unix timestamp of request
|
|
117
|
+
- `queryHash?: string` - Hash of query for duplicate detection
|
|
118
|
+
|
|
119
|
+
**Usage:**
|
|
120
|
+
- Create log entry before Firestore operation
|
|
121
|
+
- Populate with operation details
|
|
122
|
+
- Store for analytics and monitoring
|
|
123
|
+
- Use queryHash for deduplication
|
|
124
|
+
|
|
125
|
+
### RequestType
|
|
126
|
+
|
|
127
|
+
**Import From:** `src/firestore/domain/entities`
|
|
128
|
+
|
|
129
|
+
**Purpose:** Type of Firestore request
|
|
130
|
+
|
|
131
|
+
**Values:**
|
|
132
|
+
- `'read'` - Query/get operations
|
|
133
|
+
- `'write'` - Create/update operations
|
|
134
|
+
- `'delete'` - Delete operations
|
|
135
|
+
|
|
136
|
+
**Usage:**
|
|
137
|
+
- Categorize operations for quota tracking
|
|
138
|
+
- Separate read/write/delete costs
|
|
139
|
+
- Filter logs by operation type
|
|
140
|
+
- Generate statistics by type
|
|
141
|
+
|
|
142
|
+
### RequestStats
|
|
143
|
+
|
|
144
|
+
**Import From:** `src/firestore/domain/entities`
|
|
145
|
+
|
|
146
|
+
**Purpose:** Statistics summary for Firestore requests
|
|
147
|
+
|
|
148
|
+
**Properties:**
|
|
149
|
+
- `totalReads: number` - Total read operations
|
|
150
|
+
- `totalWrites: number` - Total write operations
|
|
151
|
+
- `totalDeletes: number` - Total delete operations
|
|
152
|
+
- `totalRequests: number` - Total all operations
|
|
153
|
+
- `avgDocCount: number` - Average documents per request
|
|
154
|
+
|
|
155
|
+
**Usage:**
|
|
156
|
+
- Calculate from array of RequestLog
|
|
157
|
+
- Display usage statistics
|
|
158
|
+
- Monitor quota consumption
|
|
159
|
+
- Generate reports
|
|
160
|
+
|
|
161
|
+
## Helper Functions
|
|
162
|
+
|
|
163
|
+
### Creating Request Logs
|
|
164
|
+
|
|
165
|
+
**Strategy:** Create log entry before each Firestore operation.
|
|
166
|
+
|
|
167
|
+
**Properties to Set:**
|
|
168
|
+
1. `type` - Operation type (read/write/delete)
|
|
169
|
+
2. `collectionName` - Target collection
|
|
170
|
+
3. `documentCount` - Affected document count
|
|
171
|
+
4. `timestamp` - Current timestamp
|
|
172
|
+
5. `queryHash` - Optional query identifier
|
|
173
|
+
|
|
174
|
+
**When to Create:**
|
|
175
|
+
- Before repository query execution
|
|
176
|
+
- In middleware before operation
|
|
177
|
+
- After operation completes
|
|
178
|
+
- On operation errors (log failed attempt)
|
|
179
|
+
|
|
180
|
+
### Calculating Statistics
|
|
181
|
+
|
|
182
|
+
**Strategy:** Aggregate RequestLog array into RequestStats.
|
|
183
|
+
|
|
184
|
+
**Calculation:**
|
|
185
|
+
1. Filter logs by type for each count
|
|
186
|
+
2. Sum document counts
|
|
187
|
+
3. Calculate average document count
|
|
188
|
+
4. Return statistics object
|
|
189
|
+
|
|
190
|
+
**When to Calculate:**
|
|
191
|
+
- On-demand statistics display
|
|
192
|
+
- Periodic reporting (daily/weekly)
|
|
193
|
+
- After quota threshold warning
|
|
194
|
+
- Performance monitoring
|
|
195
|
+
|
|
196
|
+
## Common Mistakes to Avoid
|
|
197
|
+
|
|
198
|
+
1. ❌ Logging sensitive data in request logs
|
|
199
|
+
- ✅ Only log operation metadata
|
|
200
|
+
|
|
201
|
+
2. ❌ Not logging all operations
|
|
202
|
+
- ✅ Log every Firestore operation
|
|
203
|
+
|
|
204
|
+
3. ❌ Storing logs indefinitely
|
|
205
|
+
- ✅ Clean up old logs regularly
|
|
206
|
+
|
|
207
|
+
4. ❌ Not using types
|
|
208
|
+
- ✅ Always use RequestLog type
|
|
209
|
+
|
|
210
|
+
5. ❌ Logging in production database
|
|
211
|
+
- ✅ Use logging service or external tool
|
|
212
|
+
|
|
213
|
+
## AI Agent Instructions
|
|
214
|
+
|
|
215
|
+
### When Adding Request Logging
|
|
216
|
+
|
|
217
|
+
1. Import types from `src/firestore/domain/entities`
|
|
218
|
+
2. Create RequestLog before each operation
|
|
219
|
+
3. Populate all required fields
|
|
220
|
+
4. Include queryHash for duplicates
|
|
221
|
+
5. Log operation completion
|
|
222
|
+
|
|
223
|
+
### When Calculating Statistics
|
|
224
|
+
|
|
225
|
+
1. Collect all RequestLog entries
|
|
226
|
+
2. Filter by type for counts
|
|
227
|
+
3. Calculate aggregates
|
|
228
|
+
4. Return RequestStats object
|
|
229
|
+
5. Handle empty log array
|
|
230
|
+
|
|
231
|
+
### When Using for Analytics
|
|
232
|
+
|
|
233
|
+
1. Export logs periodically
|
|
234
|
+
2. Analyze query patterns
|
|
235
|
+
3. Identify most accessed collections
|
|
236
|
+
4. Detect performance issues
|
|
237
|
+
5. Generate usage reports
|
|
238
|
+
|
|
239
|
+
## Performance Considerations
|
|
240
|
+
|
|
241
|
+
### Logging Overhead
|
|
242
|
+
|
|
243
|
+
**Minimal Impact:**
|
|
244
|
+
- Type checking at compile time (not runtime)
|
|
245
|
+
- Simple object creation
|
|
246
|
+
- No complex transformations
|
|
247
|
+
- Acceptable for all operations
|
|
248
|
+
|
|
249
|
+
### Storage Strategy
|
|
250
|
+
|
|
251
|
+
**Don't Store in Production Database:**
|
|
252
|
+
- Use external logging service
|
|
253
|
+
- Export logs for analysis
|
|
254
|
+
- Keep logs in memory temporarily
|
|
255
|
+
- Aggregate before storage
|
|
256
|
+
|
|
257
|
+
### Log Cleanup
|
|
258
|
+
|
|
259
|
+
**Regular Cleanup:**
|
|
260
|
+
- Remove logs older than retention period
|
|
261
|
+
- Aggregate before deletion
|
|
262
|
+
- Keep statistics for long-term
|
|
263
|
+
- Compress old logs if needed
|
|
264
|
+
|
|
265
|
+
## Related Documentation
|
|
266
|
+
|
|
267
|
+
- [Firestore Module README](../../README.md)
|
|
268
|
+
- [Request Logger Service README](../../infrastructure/services/request-logger-service/README.md)
|
|
269
|
+
- [Quota Tracking README](../../infrastructure/middleware/quota-tracking/README.md)
|
|
270
|
+
|
|
271
|
+
## API Reference
|
|
272
|
+
|
|
273
|
+
### Main Types
|
|
274
|
+
|
|
275
|
+
**Import Path:** `src/firestore/domain/entities`
|
|
276
|
+
|
|
277
|
+
| Type | Purpose | Properties |
|
|
278
|
+
|------|---------|------------|
|
|
279
|
+
| `RequestLog` | Single request log | type, collectionName, documentCount, timestamp, queryHash |
|
|
280
|
+
| `RequestType` | Operation type | 'read' \| 'write' \| 'delete' |
|
|
281
|
+
| `RequestStats` | Usage statistics | totalReads, totalWrites, totalDeletes, totalRequests, avgDocCount |
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
**Last Updated:** 2025-01-08
|
|
286
|
+
**Maintainer:** Firestore Module Team
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
# Firestore Errors
|
|
2
|
+
|
|
3
|
+
Firebase Firestore error types, error detection, and error handling utilities.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides custom error classes for Firestore operations, quota error detection, error handling utilities, and retry logic for transient failures.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Firestore Errors
|
|
12
|
+
|
|
13
|
+
1. **USE** custom error classes (not Firebase errors directly)
|
|
14
|
+
2. **CHECK** error types with instanceof
|
|
15
|
+
3. **HANDLE** quota errors appropriately
|
|
16
|
+
4. **RETRY** transient errors automatically
|
|
17
|
+
5. **LOG** errors for debugging
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Use custom error classes** - Import from firestore module
|
|
22
|
+
2. **Check error types** - Use instanceof for type checking
|
|
23
|
+
3. **Handle quota errors** - Show user-friendly messages
|
|
24
|
+
4. **Use retry logic** - Retry transient errors
|
|
25
|
+
5. **Provide context** - Include error details in logs
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Throw primitive values (always Error instances)
|
|
32
|
+
- Ignore error types
|
|
33
|
+
- Assume all errors are retryable
|
|
34
|
+
- Show technical error messages to users
|
|
35
|
+
- Catch and suppress errors silently
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Not checking error types before handling
|
|
40
|
+
- Retrying non-retryable errors
|
|
41
|
+
- Generic error handling
|
|
42
|
+
- Not logging errors
|
|
43
|
+
- Missing error context
|
|
44
|
+
|
|
45
|
+
## Error Classes
|
|
46
|
+
|
|
47
|
+
### FirebaseFirestoreError
|
|
48
|
+
|
|
49
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
50
|
+
|
|
51
|
+
**Purpose:** Base error class for all Firestore errors
|
|
52
|
+
|
|
53
|
+
**Properties:**
|
|
54
|
+
- `code: string` - Error code for programmatic handling
|
|
55
|
+
- `message: string` - Human-readable error message
|
|
56
|
+
|
|
57
|
+
**Usage:**
|
|
58
|
+
- Base class for all Firestore errors
|
|
59
|
+
- Type checking with instanceof
|
|
60
|
+
- Error code for conditional logic
|
|
61
|
+
|
|
62
|
+
**When to Use:**
|
|
63
|
+
- Throwing custom Firestore errors
|
|
64
|
+
- Catching and handling Firestore errors
|
|
65
|
+
- Type-safe error handling
|
|
66
|
+
|
|
67
|
+
### FirebaseFirestoreInitializationError
|
|
68
|
+
|
|
69
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
70
|
+
|
|
71
|
+
**Purpose:** Error thrown when Firestore fails to initialize
|
|
72
|
+
|
|
73
|
+
**Extends:** FirebaseFirestoreError
|
|
74
|
+
|
|
75
|
+
**Usage:**
|
|
76
|
+
- Initialization failures
|
|
77
|
+
- Configuration errors
|
|
78
|
+
- Firebase setup issues
|
|
79
|
+
|
|
80
|
+
**When to Use:**
|
|
81
|
+
- Firestore not initialized
|
|
82
|
+
- Invalid Firebase config
|
|
83
|
+
- Initialization timeout
|
|
84
|
+
|
|
85
|
+
### FirebaseFirestoreQuotaError
|
|
86
|
+
|
|
87
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
88
|
+
|
|
89
|
+
**Purpose:** Error thrown when Firestore quota is exceeded
|
|
90
|
+
|
|
91
|
+
**Extends:** FirebaseFirestoreError
|
|
92
|
+
|
|
93
|
+
**Properties:**
|
|
94
|
+
- `quotaType: 'read' | 'write' | 'delete'` - Type of quota exceeded
|
|
95
|
+
- `usage: QuotaStatus` - Quota usage details
|
|
96
|
+
|
|
97
|
+
**Usage:**
|
|
98
|
+
- Quota exceeded scenarios
|
|
99
|
+
- Usage tracking
|
|
100
|
+
- Cost management
|
|
101
|
+
|
|
102
|
+
**When to Use:**
|
|
103
|
+
- Read quota exceeded (daily limit)
|
|
104
|
+
- Write quota exceeded (daily limit)
|
|
105
|
+
- Delete quota exceeded (monthly limit)
|
|
106
|
+
|
|
107
|
+
## Error Detection
|
|
108
|
+
|
|
109
|
+
### isQuotaError
|
|
110
|
+
|
|
111
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
112
|
+
|
|
113
|
+
**Purpose:** Check if an error is quota-related
|
|
114
|
+
|
|
115
|
+
**Returns:** `boolean`
|
|
116
|
+
|
|
117
|
+
**Usage Strategy:**
|
|
118
|
+
1. Catch Firestore errors
|
|
119
|
+
2. Call isQuotaError(error)
|
|
120
|
+
3. Handle quota errors specifically
|
|
121
|
+
4. Show user-friendly quota message
|
|
122
|
+
5. Log quota usage for monitoring
|
|
123
|
+
|
|
124
|
+
**When to Use:**
|
|
125
|
+
- Distinguishing quota errors from other errors
|
|
126
|
+
- Showing quota-specific UI
|
|
127
|
+
- Implementing quota-based throttling
|
|
128
|
+
|
|
129
|
+
### isRetryableError
|
|
130
|
+
|
|
131
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
132
|
+
|
|
133
|
+
**Purpose:** Check if an error is retryable (transient)
|
|
134
|
+
|
|
135
|
+
**Returns:** `boolean`
|
|
136
|
+
|
|
137
|
+
**Retryable Errors:**
|
|
138
|
+
- Network errors
|
|
139
|
+
- Timeout errors
|
|
140
|
+
- Service unavailable
|
|
141
|
+
- Deadline exceeded
|
|
142
|
+
- Aborted operations
|
|
143
|
+
|
|
144
|
+
**Non-Retryable Errors:**
|
|
145
|
+
- Permission denied
|
|
146
|
+
- Not found
|
|
147
|
+
- Invalid arguments
|
|
148
|
+
- Quota exceeded
|
|
149
|
+
- Failed precondition
|
|
150
|
+
|
|
151
|
+
**Usage Strategy:**
|
|
152
|
+
1. Catch error from operation
|
|
153
|
+
2. Check isRetryableError(error)
|
|
154
|
+
3. Retry with exponential backoff if true
|
|
155
|
+
4. Show error if false
|
|
156
|
+
5. Limit retry attempts
|
|
157
|
+
|
|
158
|
+
### getQuotaErrorMessage
|
|
159
|
+
|
|
160
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
161
|
+
|
|
162
|
+
**Purpose:** Get user-friendly quota error message
|
|
163
|
+
|
|
164
|
+
**Returns:** `string`
|
|
165
|
+
|
|
166
|
+
**Message Format:**
|
|
167
|
+
- Shows quota type (read/write/delete)
|
|
168
|
+
- Displays usage percentage
|
|
169
|
+
- Indicates limit reached
|
|
170
|
+
- Suggests next steps
|
|
171
|
+
|
|
172
|
+
**Usage Strategy:**
|
|
173
|
+
1. Check if error is quota error
|
|
174
|
+
2. Call getQuotaErrorMessage(error)
|
|
175
|
+
3. Display message to user
|
|
176
|
+
4. Provide upgrade options
|
|
177
|
+
5. Log technical details
|
|
178
|
+
|
|
179
|
+
## Error Handling Strategies
|
|
180
|
+
|
|
181
|
+
### For Quota Errors
|
|
182
|
+
|
|
183
|
+
**Strategy:** Detect and handle quota exceeded scenarios.
|
|
184
|
+
|
|
185
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
186
|
+
|
|
187
|
+
**When to Use:**
|
|
188
|
+
- Daily read quota exceeded
|
|
189
|
+
- Daily write quota exceeded
|
|
190
|
+
- Monthly delete quota exceeded
|
|
191
|
+
|
|
192
|
+
**Handling Strategy:**
|
|
193
|
+
1. Catch error from Firestore operation
|
|
194
|
+
2. Check isQuotaError(error)
|
|
195
|
+
3. Get user-friendly message
|
|
196
|
+
4. Display upgrade option
|
|
197
|
+
5. Log quota usage for monitoring
|
|
198
|
+
6. Implement throttling if needed
|
|
199
|
+
|
|
200
|
+
**User Experience:**
|
|
201
|
+
- Clear message about quota exceeded
|
|
202
|
+
- Show usage percentage
|
|
203
|
+
- Offer upgrade or wait option
|
|
204
|
+
- Provide quota reset time
|
|
205
|
+
|
|
206
|
+
### For Transient Errors
|
|
207
|
+
|
|
208
|
+
**Strategy:** Retry transient failures with exponential backoff.
|
|
209
|
+
|
|
210
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
211
|
+
|
|
212
|
+
**When to Use:**
|
|
213
|
+
- Network failures
|
|
214
|
+
- Service unavailable
|
|
215
|
+
- Timeout errors
|
|
216
|
+
- Temporary issues
|
|
217
|
+
|
|
218
|
+
**Retry Strategy:**
|
|
219
|
+
1. Check isRetryableError(error)
|
|
220
|
+
2. Wait with exponential backoff (1s, 2s, 4s)
|
|
221
|
+
3. Retry operation
|
|
222
|
+
4. Limit retries to 3 attempts
|
|
223
|
+
5. Give up after max retries
|
|
224
|
+
|
|
225
|
+
**Exponential Backoff:**
|
|
226
|
+
- First retry: 1000ms (1 second)
|
|
227
|
+
- Second retry: 2000ms (2 seconds)
|
|
228
|
+
- Third retry: 4000ms (4 seconds)
|
|
229
|
+
- Max total wait: ~7 seconds
|
|
230
|
+
|
|
231
|
+
### For Initialization Errors
|
|
232
|
+
|
|
233
|
+
**Strategy:** Handle Firestore initialization failures.
|
|
234
|
+
|
|
235
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
236
|
+
|
|
237
|
+
**When to Use:**
|
|
238
|
+
- Firebase config missing
|
|
239
|
+
- Invalid Firebase config
|
|
240
|
+
- Network issues during init
|
|
241
|
+
- Permission issues
|
|
242
|
+
|
|
243
|
+
**Handling Strategy:**
|
|
244
|
+
1. Catch initialization error
|
|
245
|
+
2. Check error type
|
|
246
|
+
3. Show setup error message
|
|
247
|
+
4. Provide setup instructions
|
|
248
|
+
5. Offer retry option
|
|
249
|
+
|
|
250
|
+
## Error Codes Reference
|
|
251
|
+
|
|
252
|
+
### Common Error Codes
|
|
253
|
+
|
|
254
|
+
**Import From:** Error.code property
|
|
255
|
+
|
|
256
|
+
| Error Code | Description | Retryable | User Action |
|
|
257
|
+
|------------|-------------|-----------|-------------|
|
|
258
|
+
| `INITIALIZATION_FAILED` | Failed to initialize Firestore | Yes | Check config, retry |
|
|
259
|
+
| `QUOTA_EXCEEDED` | Quota limit exceeded | No | Wait or upgrade plan |
|
|
260
|
+
| `NOT_FOUND` | Document not found | No | Check document ID |
|
|
261
|
+
| `PERMISSION_DENIED` | Insufficient permissions | No | Check security rules |
|
|
262
|
+
| `UNAVAILABLE` | Service unavailable | Yes | Retry after delay |
|
|
263
|
+
| `DEADLINE_EXCEEDED` | Request timeout | Yes | Retry after delay |
|
|
264
|
+
| `ALREADY_EXISTS` | Document already exists | No | Check before create |
|
|
265
|
+
| `INVALID_ARGUMENT` | Invalid argument | No | Fix argument value |
|
|
266
|
+
| `FAILED_PRECONDITION` | Failed precondition | No | Fix precondition |
|
|
267
|
+
| `ABORTED` | Operation aborted | Yes | Retry operation |
|
|
268
|
+
|
|
269
|
+
## Common Mistakes to Avoid
|
|
270
|
+
|
|
271
|
+
1. ❌ Not checking error types
|
|
272
|
+
- ✅ Use instanceof for type checking
|
|
273
|
+
|
|
274
|
+
2. ❌ Retrying non-retryable errors
|
|
275
|
+
- ✅ Check isRetryableError() first
|
|
276
|
+
|
|
277
|
+
3. ❌ Showing technical messages to users
|
|
278
|
+
- ✅ Use getQuotaErrorMessage() for user-friendly messages
|
|
279
|
+
|
|
280
|
+
4. ❌ Not logging errors
|
|
281
|
+
- ✅ Log all errors with context
|
|
282
|
+
|
|
283
|
+
5. ❌ Suppressing errors silently
|
|
284
|
+
- ✅ Always handle or rethrow errors
|
|
285
|
+
|
|
286
|
+
## AI Agent Instructions
|
|
287
|
+
|
|
288
|
+
### When Handling Firestore Errors
|
|
289
|
+
|
|
290
|
+
1. Wrap operations in try-catch
|
|
291
|
+
2. Check error type with instanceof
|
|
292
|
+
3. Handle quota errors separately
|
|
293
|
+
4. Check if retryable with isRetryableError()
|
|
294
|
+
5. Retry with backoff if appropriate
|
|
295
|
+
6. Log errors with context
|
|
296
|
+
7. Show user-friendly messages
|
|
297
|
+
|
|
298
|
+
### When Implementing Retry Logic
|
|
299
|
+
|
|
300
|
+
1. Check isRetryableError(error)
|
|
301
|
+
2. Use exponential backoff (2^n seconds)
|
|
302
|
+
3. Limit retries to 3 attempts
|
|
303
|
+
4. Log retry attempts
|
|
304
|
+
5. Give up after max retries
|
|
305
|
+
6. Show error to user
|
|
306
|
+
|
|
307
|
+
### When Handling Quota Errors
|
|
308
|
+
|
|
309
|
+
1. Check isQuotaError(error)
|
|
310
|
+
2. Get user-friendly message
|
|
311
|
+
3. Display quota usage
|
|
312
|
+
4. Show upgrade option
|
|
313
|
+
5. Log quota exceeded event
|
|
314
|
+
6. Implement throttling if needed
|
|
315
|
+
|
|
316
|
+
## Code Quality Standards
|
|
317
|
+
|
|
318
|
+
### Error Handling
|
|
319
|
+
|
|
320
|
+
- Always use custom error classes
|
|
321
|
+
- Check error types before handling
|
|
322
|
+
- Provide error context
|
|
323
|
+
- Log errors appropriately
|
|
324
|
+
- Show user-friendly messages
|
|
325
|
+
|
|
326
|
+
### Type Safety
|
|
327
|
+
|
|
328
|
+
- Use instanceof for type checking
|
|
329
|
+
- Never use `any` for errors
|
|
330
|
+
- Type all error parameters
|
|
331
|
+
- Use discriminated unions
|
|
332
|
+
- Export error classes
|
|
333
|
+
|
|
334
|
+
### Retry Logic
|
|
335
|
+
|
|
336
|
+
- Use exponential backoff
|
|
337
|
+
- Limit retry attempts
|
|
338
|
+
- Log retry attempts
|
|
339
|
+
- Give up after max retries
|
|
340
|
+
- Don't retry non-retryable errors
|
|
341
|
+
|
|
342
|
+
## Performance Considerations
|
|
343
|
+
|
|
344
|
+
### Retry Overhead
|
|
345
|
+
|
|
346
|
+
- Retries add latency (up to 7 seconds)
|
|
347
|
+
- Use retries only for transient errors
|
|
348
|
+
- Limit retry attempts
|
|
349
|
+
- Consider circuit breaker pattern
|
|
350
|
+
- Monitor retry success rate
|
|
351
|
+
|
|
352
|
+
### Error Logging
|
|
353
|
+
|
|
354
|
+
- Log errors asynchronously
|
|
355
|
+
- Don't block on logging
|
|
356
|
+
- Use error tracking service
|
|
357
|
+
- Include context in logs
|
|
358
|
+
- Sanitize sensitive data
|
|
359
|
+
|
|
360
|
+
## Related Documentation
|
|
361
|
+
|
|
362
|
+
- [Firestore Module README](../../README.md)
|
|
363
|
+
- [Quota Error Detector README](../../utils/quota-error-detector/README.md)
|
|
364
|
+
- [Firestore Constants README](../constants/README.md)
|
|
365
|
+
|
|
366
|
+
## API Reference
|
|
367
|
+
|
|
368
|
+
### Error Classes
|
|
369
|
+
|
|
370
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
371
|
+
|
|
372
|
+
| Class | Constructor Parameters | Description |
|
|
373
|
+
|-------|----------------------|-------------|
|
|
374
|
+
| `FirebaseFirestoreError` | `(message: string, code: string)` | Base Firestore error |
|
|
375
|
+
| `FirebaseFirestoreInitializationError` | `(message: string)` | Init error |
|
|
376
|
+
| `FirebaseFirestoreQuotaError` | `(quotaType, usage: QuotaStatus)` | Quota exceeded error |
|
|
377
|
+
|
|
378
|
+
### Detection Functions
|
|
379
|
+
|
|
380
|
+
| Function | Parameters | Returns | Description |
|
|
381
|
+
|----------|-----------|---------|-------------|
|
|
382
|
+
| `isQuotaError` | `(error: unknown)` | `boolean` | Check if quota error |
|
|
383
|
+
| `isRetryableError` | `(error: unknown)` | `boolean` | Check if retryable |
|
|
384
|
+
| `getQuotaErrorMessage` | `(error: FirebaseFirestoreQuotaError)` | `string` | Get user-friendly message |
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
**Last Updated:** 2025-01-08
|
|
389
|
+
**Maintainer:** Firestore Module Team
|