@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.
- package/README.md +277 -0
- package/package.json +10 -5
- 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/config/initializers/FirebaseAuthInitializer.ts +1 -1
- package/src/auth/infrastructure/services/README.md +346 -0
- package/src/auth/infrastructure/stores/README.md +407 -0
- package/src/auth/infrastructure/stores/auth.store.ts +1 -1
- package/src/auth/presentation/hooks/README.md +442 -0
- package/src/auth/presentation/hooks/useAnonymousAuth.ts +4 -4
- package/src/auth/presentation/hooks/utils/auth-state-change.handler.ts +1 -1
- 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/FirestoreClient.ts +1 -1
- package/src/firestore/infrastructure/config/README.md +239 -0
- package/src/firestore/infrastructure/middleware/README.md +316 -0
- package/src/firestore/infrastructure/repositories/BaseRepository.ts +1 -1
- package/src/firestore/infrastructure/repositories/README.md +425 -0
- package/src/firestore/infrastructure/services/README.md +332 -0
- package/src/firestore/infrastructure/services/RequestLoggerService.ts +4 -4
- 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/FirebaseClient.ts +1 -1
- 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,325 @@
|
|
|
1
|
+
# Firestore Domain
|
|
2
|
+
|
|
3
|
+
Domain layer for Firestore module containing business logic, entities, value objects, errors, and domain services.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Implements Domain-Driven Design (DDD) principles for Firestore, separating business logic from infrastructure concerns and providing a clean architecture.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Firestore Domain
|
|
12
|
+
|
|
13
|
+
1. **UNDERSTAND** DDD architecture (domain → infrastructure → presentation)
|
|
14
|
+
2. **USE** domain entities (not infrastructure)
|
|
15
|
+
3. **NEVER** import Firebase SDK in domain layer
|
|
16
|
+
4. **DEFINE** business logic in domain
|
|
17
|
+
5. **KEEP** domain layer Firebase-free
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Keep domain Firebase-free** - No Firebase imports in domain
|
|
22
|
+
2. **Define entities** - Business entities with behavior
|
|
23
|
+
3. **Create value objects** - Immutable value types
|
|
24
|
+
4. **Define domain errors** - Custom error classes
|
|
25
|
+
5. **Write domain services** - Business logic services
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Import Firebase SDK in domain layer
|
|
32
|
+
- Mix infrastructure concerns in domain
|
|
33
|
+
- Create anemic domain models (data without behavior)
|
|
34
|
+
- Skip domain validation
|
|
35
|
+
- Put business logic in infrastructure
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Leaking domain logic to infrastructure
|
|
40
|
+
- Not validating business rules
|
|
41
|
+
- Missing domain entities
|
|
42
|
+
- Complex domain services
|
|
43
|
+
- Unclear domain boundaries
|
|
44
|
+
|
|
45
|
+
## Domain Layer Structure
|
|
46
|
+
|
|
47
|
+
### Organization
|
|
48
|
+
|
|
49
|
+
**Import From:** `src/firestore/domain`
|
|
50
|
+
|
|
51
|
+
**Structure:**
|
|
52
|
+
- `entities/` - Business entities (QuotaMetrics, RequestLog)
|
|
53
|
+
- `services/` - Domain services (QuotaCalculator)
|
|
54
|
+
- `constants/` - Domain constants (QuotaLimits)
|
|
55
|
+
- `errors/` - Domain errors (FirebaseFirestoreError)
|
|
56
|
+
|
|
57
|
+
**Principles:**
|
|
58
|
+
- No external dependencies (Firebase-free)
|
|
59
|
+
- Pure business logic
|
|
60
|
+
- Type-safe entities
|
|
61
|
+
- Clear boundaries
|
|
62
|
+
- Testable in isolation
|
|
63
|
+
|
|
64
|
+
## Entities
|
|
65
|
+
|
|
66
|
+
### QuotaMetrics
|
|
67
|
+
|
|
68
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain`
|
|
69
|
+
|
|
70
|
+
**Purpose:** Represents Firestore quota usage metrics
|
|
71
|
+
|
|
72
|
+
**Properties:**
|
|
73
|
+
- `totalReads: number` - Total read operations
|
|
74
|
+
- `totalWrites: number` - Total write operations
|
|
75
|
+
- `totalDeletes: number` - Total delete operations
|
|
76
|
+
- `reads: QuotaStatus` - Read quota details
|
|
77
|
+
- `writes: QuotaStatus` - Write quota details
|
|
78
|
+
- `deletes: QuotaStatus` - Delete quota details
|
|
79
|
+
|
|
80
|
+
**QuotaStatus Properties:**
|
|
81
|
+
- `used: number` - Amount used
|
|
82
|
+
- `limit: number` - Total limit
|
|
83
|
+
- `percentage: number` - Usage percentage (0-100)
|
|
84
|
+
|
|
85
|
+
**Usage:**
|
|
86
|
+
- Track quota usage
|
|
87
|
+
- Display usage to users
|
|
88
|
+
- Check thresholds
|
|
89
|
+
- Calculate remaining quota
|
|
90
|
+
- Monitor trends
|
|
91
|
+
|
|
92
|
+
**When to Use:**
|
|
93
|
+
- After quota calculations
|
|
94
|
+
- Displaying quota status
|
|
95
|
+
- Checking thresholds
|
|
96
|
+
- Monitoring usage
|
|
97
|
+
- Cost analysis
|
|
98
|
+
|
|
99
|
+
### RequestLog
|
|
100
|
+
|
|
101
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain`
|
|
102
|
+
|
|
103
|
+
**Purpose:** Log entry for a Firestore request
|
|
104
|
+
|
|
105
|
+
**Properties:**
|
|
106
|
+
- `type: RequestType` - Operation type ('read', 'write', 'delete')
|
|
107
|
+
- `collectionName: string` - Collection being accessed
|
|
108
|
+
- `documentCount: number` - Number of documents affected
|
|
109
|
+
- `timestamp: number` - Unix timestamp of request
|
|
110
|
+
- `queryHash?: string` - Hash of query for duplicate detection
|
|
111
|
+
|
|
112
|
+
**Usage:**
|
|
113
|
+
- Create log entry before operation
|
|
114
|
+
- Populate with operation details
|
|
115
|
+
- Store for analytics and monitoring
|
|
116
|
+
- Use queryHash for deduplication
|
|
117
|
+
|
|
118
|
+
**When to Use:**
|
|
119
|
+
- Repository operations (read, write, delete)
|
|
120
|
+
- Quota tracking middleware
|
|
121
|
+
- Performance monitoring
|
|
122
|
+
- Analytics and reporting
|
|
123
|
+
|
|
124
|
+
## Value Objects
|
|
125
|
+
|
|
126
|
+
### QuotaStatus
|
|
127
|
+
|
|
128
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain`
|
|
129
|
+
|
|
130
|
+
**Purpose:** Represents quota usage status for a single operation type
|
|
131
|
+
|
|
132
|
+
**Properties:**
|
|
133
|
+
- `used: number` - Amount used
|
|
134
|
+
- `limit: number` - Total limit
|
|
135
|
+
- `percentage: number` - Usage percentage
|
|
136
|
+
|
|
137
|
+
**Characteristics:**
|
|
138
|
+
- Immutable value object
|
|
139
|
+
- Used in QuotaMetrics
|
|
140
|
+
- Calculated from raw counts
|
|
141
|
+
- Used for threshold checking
|
|
142
|
+
|
|
143
|
+
**When to Use:**
|
|
144
|
+
- Calculating quota usage
|
|
145
|
+
- Checking thresholds
|
|
146
|
+
- Displaying quota status
|
|
147
|
+
- Monitoring limits
|
|
148
|
+
|
|
149
|
+
## Domain Services
|
|
150
|
+
|
|
151
|
+
### QuotaCalculator
|
|
152
|
+
|
|
153
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/services`
|
|
154
|
+
|
|
155
|
+
**Purpose:** Business logic for quota calculations
|
|
156
|
+
|
|
157
|
+
**Responsibilities:**
|
|
158
|
+
- Calculate quota usage percentages
|
|
159
|
+
- Check quota thresholds
|
|
160
|
+
- Calculate remaining quota
|
|
161
|
+
- Validate quota limits
|
|
162
|
+
|
|
163
|
+
**Methods:**
|
|
164
|
+
- Calculate usage from operation counts
|
|
165
|
+
- Compare against thresholds
|
|
166
|
+
- Return QuotaMetrics object
|
|
167
|
+
|
|
168
|
+
**When to Use:**
|
|
169
|
+
- After batch operations
|
|
170
|
+
- Displaying quota status
|
|
171
|
+
- Checking before large operations
|
|
172
|
+
- Monitoring usage trends
|
|
173
|
+
|
|
174
|
+
## Domain Constants
|
|
175
|
+
|
|
176
|
+
### QuotaLimits
|
|
177
|
+
|
|
178
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/constants`
|
|
179
|
+
|
|
180
|
+
**Purpose:** Firebase free tier quota limits
|
|
181
|
+
|
|
182
|
+
**Constants:**
|
|
183
|
+
- Daily read limit (50,000)
|
|
184
|
+
- Daily write limit (20,000)
|
|
185
|
+
- Monthly delete limit (20,000)
|
|
186
|
+
|
|
187
|
+
**Usage:**
|
|
188
|
+
- Quota calculations
|
|
189
|
+
- Display limits to users
|
|
190
|
+
- Calculate remaining quota
|
|
191
|
+
- Set up monitoring
|
|
192
|
+
|
|
193
|
+
**When to Use:**
|
|
194
|
+
- Calculating quota usage
|
|
195
|
+
- Displaying quota information
|
|
196
|
+
- Setting up alerts
|
|
197
|
+
- Checking remaining quota
|
|
198
|
+
|
|
199
|
+
## Domain Errors
|
|
200
|
+
|
|
201
|
+
### FirebaseFirestoreError
|
|
202
|
+
|
|
203
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/errors`
|
|
204
|
+
|
|
205
|
+
**Purpose:** Base error class for all Firestore errors
|
|
206
|
+
|
|
207
|
+
**Properties:**
|
|
208
|
+
- `code: string` - Error code
|
|
209
|
+
- `message: string` - Error message
|
|
210
|
+
|
|
211
|
+
**Hierarchy:**
|
|
212
|
+
- FirebaseFirestoreError (base)
|
|
213
|
+
- FirebaseFirestoreInitializationError
|
|
214
|
+
- FirebaseFirestoreQuotaError
|
|
215
|
+
|
|
216
|
+
**When to Use:**
|
|
217
|
+
- Throwing custom Firestore errors
|
|
218
|
+
- Type-safe error handling
|
|
219
|
+
- Error code for conditional logic
|
|
220
|
+
- Structured error information
|
|
221
|
+
|
|
222
|
+
## Common Mistakes to Avoid
|
|
223
|
+
|
|
224
|
+
1. ❌ Importing Firebase in domain layer
|
|
225
|
+
- ✅ Keep domain Firebase-free
|
|
226
|
+
|
|
227
|
+
2. ❌ Anemic domain models
|
|
228
|
+
- ✅ Add behavior to entities
|
|
229
|
+
|
|
230
|
+
3. ❌ Business logic in infrastructure
|
|
231
|
+
- ✅ Put business logic in domain
|
|
232
|
+
|
|
233
|
+
4. ❌ Not validating business rules
|
|
234
|
+
- ✅ Validate in domain layer
|
|
235
|
+
|
|
236
|
+
5. ❌ Leaking domain logic
|
|
237
|
+
- ✅ Keep domain logic contained
|
|
238
|
+
|
|
239
|
+
## AI Agent Instructions
|
|
240
|
+
|
|
241
|
+
### When Creating Domain Entity
|
|
242
|
+
|
|
243
|
+
1. Define entity interface
|
|
244
|
+
2. Add business logic methods
|
|
245
|
+
3. Validate invariants
|
|
246
|
+
4. Keep Firebase-free
|
|
247
|
+
5. Export for infrastructure use
|
|
248
|
+
|
|
249
|
+
### When Creating Domain Service
|
|
250
|
+
|
|
251
|
+
1. Identify business logic
|
|
252
|
+
2. Create service class
|
|
253
|
+
3. Implement business rules
|
|
254
|
+
4. Keep pure functions
|
|
255
|
+
5. Test in isolation
|
|
256
|
+
|
|
257
|
+
### When Creating Domain Error
|
|
258
|
+
|
|
259
|
+
1. Extend base error class
|
|
260
|
+
2. Add error code
|
|
261
|
+
3. Provide clear message
|
|
262
|
+
4. Include context
|
|
263
|
+
5. Export for use
|
|
264
|
+
|
|
265
|
+
## Code Quality Standards
|
|
266
|
+
|
|
267
|
+
### Domain Layer
|
|
268
|
+
|
|
269
|
+
- No Firebase imports
|
|
270
|
+
- Pure TypeScript
|
|
271
|
+
- Business logic only
|
|
272
|
+
- Type-safe entities
|
|
273
|
+
- Clear interfaces
|
|
274
|
+
|
|
275
|
+
### Testing
|
|
276
|
+
|
|
277
|
+
- Test domain in isolation
|
|
278
|
+
- Mock infrastructure
|
|
279
|
+
- Test business rules
|
|
280
|
+
- Validate invariants
|
|
281
|
+
- Unit test coverage
|
|
282
|
+
|
|
283
|
+
## Related Documentation
|
|
284
|
+
|
|
285
|
+
- [Firestore Module README](../../README.md)
|
|
286
|
+
- [Firestore Infrastructure README](../../infrastructure/README.md)
|
|
287
|
+
- [Firestore Errors README](../errors/README.md)
|
|
288
|
+
- [Quota Constants README](../constants/README.md)
|
|
289
|
+
|
|
290
|
+
## Architecture
|
|
291
|
+
|
|
292
|
+
### Domain Layer Responsibilities
|
|
293
|
+
|
|
294
|
+
**What Domain Does:**
|
|
295
|
+
- Defines business entities
|
|
296
|
+
- Contains business logic
|
|
297
|
+
- Validates business rules
|
|
298
|
+
- Provides domain services
|
|
299
|
+
- Defines domain errors
|
|
300
|
+
|
|
301
|
+
**What Domain Doesn't Do:**
|
|
302
|
+
- No Firebase SDK usage
|
|
303
|
+
- No database operations
|
|
304
|
+
- No HTTP requests
|
|
305
|
+
- No external integrations
|
|
306
|
+
- No UI concerns
|
|
307
|
+
|
|
308
|
+
### DDD Principles
|
|
309
|
+
|
|
310
|
+
**Strategic Patterns:**
|
|
311
|
+
- Entities (identity-based objects)
|
|
312
|
+
- Value Objects (immutable values)
|
|
313
|
+
- Domain Services (stateless operations)
|
|
314
|
+
- Aggregates (consistency boundaries)
|
|
315
|
+
- Repositories (infrastructure concern)
|
|
316
|
+
|
|
317
|
+
**Tactical Patterns:**
|
|
318
|
+
- Factory (creation)
|
|
319
|
+
- Strategy (algorithms)
|
|
320
|
+
- Specification (business rules)
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
**Last Updated:** 2025-01-08
|
|
325
|
+
**Maintainer:** Firestore Module Team
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# Firestore Constants
|
|
2
|
+
|
|
3
|
+
Firestore quota limits, thresholds, and constants for Firebase operations.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides constants and configuration values for Firestore quota management including free tier limits, warning thresholds, and utility functions for quota calculations.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Firestore Constants
|
|
12
|
+
|
|
13
|
+
1. **USE** constants for all quota values
|
|
14
|
+
2. **CHECK** quota thresholds before operations
|
|
15
|
+
3. **CALCULATE** quota usage with utility functions
|
|
16
|
+
4. **WARN** users when approaching limits
|
|
17
|
+
5. **NEVER** hardcode quota values
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Use constants** - Import FREE_TIER_LIMITS and QUOTA_THRESHOLDS
|
|
22
|
+
2. **Calculate usage** - Use calculateQuotaUsage() function
|
|
23
|
+
3. **Check thresholds** - Use isQuotaThresholdReached()
|
|
24
|
+
4. **Monitor quota** - Track usage throughout the day
|
|
25
|
+
5. **Warn appropriately** - Show warnings at thresholds
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Hardcode quota values (50,000, 20,000, etc.)
|
|
32
|
+
- Ignore quota limits
|
|
33
|
+
- Skip quota monitoring
|
|
34
|
+
- Calculate quota manually
|
|
35
|
+
- Exceed free tier without warning
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Not checking quota before operations
|
|
40
|
+
- Hardcoding threshold percentages
|
|
41
|
+
- Not warning users at thresholds
|
|
42
|
+
- Calculating quota incorrectly
|
|
43
|
+
- Ignoring delete quota (monthly vs daily)
|
|
44
|
+
|
|
45
|
+
## Constants
|
|
46
|
+
|
|
47
|
+
### FREE_TIER_LIMITS
|
|
48
|
+
|
|
49
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/constants`
|
|
50
|
+
|
|
51
|
+
**Purpose:** Firebase free tier daily/monthly quota limits
|
|
52
|
+
|
|
53
|
+
**Properties:**
|
|
54
|
+
- `dailyReads: number` - Daily read limit (50,000)
|
|
55
|
+
- `dailyWrites: number` - Daily write limit (20,000)
|
|
56
|
+
- `monthlyDeletes: number` - Monthly delete limit (20,000)
|
|
57
|
+
|
|
58
|
+
**Usage:**
|
|
59
|
+
- Use for quota calculations
|
|
60
|
+
- Display limits to users
|
|
61
|
+
- Calculate remaining quota
|
|
62
|
+
- Set up monitoring
|
|
63
|
+
|
|
64
|
+
**When to Use:**
|
|
65
|
+
- Calculating quota usage
|
|
66
|
+
- Displaying quota information
|
|
67
|
+
- Checking remaining quota
|
|
68
|
+
- Setting up alerts
|
|
69
|
+
|
|
70
|
+
**Important Notes:**
|
|
71
|
+
- Reads reset daily
|
|
72
|
+
- Writes reset daily
|
|
73
|
+
- Deletes reset monthly
|
|
74
|
+
- Different reset periods
|
|
75
|
+
|
|
76
|
+
### QUOTA_THRESHOLDS
|
|
77
|
+
|
|
78
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/constants`
|
|
79
|
+
|
|
80
|
+
**Purpose:** Warning and critical threshold percentages
|
|
81
|
+
|
|
82
|
+
**Properties:**
|
|
83
|
+
- `warning: number` - Warning threshold (80%)
|
|
84
|
+
- `critical: number` - Critical threshold (90%)
|
|
85
|
+
|
|
86
|
+
**Usage:**
|
|
87
|
+
- Trigger warnings at 80%
|
|
88
|
+
- Trigger critical alerts at 90%
|
|
89
|
+
- Display warnings to users
|
|
90
|
+
- Implement throttling
|
|
91
|
+
|
|
92
|
+
**When to Use:**
|
|
93
|
+
- Checking if quota exceeded
|
|
94
|
+
- Showing warnings to users
|
|
95
|
+
- Implementing usage alerts
|
|
96
|
+
- Throttling operations
|
|
97
|
+
|
|
98
|
+
**Threshold Strategy:**
|
|
99
|
+
- Warning at 80% - Inform user
|
|
100
|
+
- Critical at 90% - Strong warning
|
|
101
|
+
- Limit at 100% - Block operations
|
|
102
|
+
- Consider upgrade prompts
|
|
103
|
+
|
|
104
|
+
## Utility Functions
|
|
105
|
+
|
|
106
|
+
### calculateQuotaUsage
|
|
107
|
+
|
|
108
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/constants`
|
|
109
|
+
|
|
110
|
+
**Purpose:** Calculate quota usage percentages from raw numbers
|
|
111
|
+
|
|
112
|
+
**Parameters:**
|
|
113
|
+
- Object with `reads`, `writes`, `deletes` counts
|
|
114
|
+
|
|
115
|
+
**Returns:** `QuotaMetrics` object with:
|
|
116
|
+
- `totalReads`, `totalWrites`, `totalDeletes`
|
|
117
|
+
- `reads: QuotaStatus` - { used, limit, percentage }
|
|
118
|
+
- `writes: QuotaStatus` - { used, limit, percentage }
|
|
119
|
+
- `deletes: QuotaStatus` - { used, limit, percentage }
|
|
120
|
+
|
|
121
|
+
**QuotaStatus Properties:**
|
|
122
|
+
- `used: number` - Amount used
|
|
123
|
+
- `limit: number` - Total limit
|
|
124
|
+
- `percentage: number` - Usage percentage (0-100)
|
|
125
|
+
|
|
126
|
+
**Usage Strategy:**
|
|
127
|
+
1. Collect operation counts
|
|
128
|
+
2. Call calculateQuotaUsage()
|
|
129
|
+
3. Check percentages for each type
|
|
130
|
+
4. Display to user if needed
|
|
131
|
+
5. Implement throttling
|
|
132
|
+
|
|
133
|
+
**When to Use:**
|
|
134
|
+
- After batch operations
|
|
135
|
+
- Displaying quota status
|
|
136
|
+
- Checking before large operations
|
|
137
|
+
- Monitoring usage trends
|
|
138
|
+
|
|
139
|
+
### isQuotaThresholdReached
|
|
140
|
+
|
|
141
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/constants`
|
|
142
|
+
|
|
143
|
+
**Purpose:** Check if quota usage has reached a specific threshold
|
|
144
|
+
|
|
145
|
+
**Parameters:**
|
|
146
|
+
- `metrics: QuotaMetrics` - From calculateQuotaUsage()
|
|
147
|
+
- `threshold: number` - Threshold percentage (80 or 90)
|
|
148
|
+
|
|
149
|
+
**Returns:** `boolean` - Whether threshold reached
|
|
150
|
+
|
|
151
|
+
**Usage Strategy:**
|
|
152
|
+
1. Calculate quota usage
|
|
153
|
+
2. Check if warning threshold reached
|
|
154
|
+
3. Check if critical threshold reached
|
|
155
|
+
4. Display appropriate warning
|
|
156
|
+
5. Throttle operations if needed
|
|
157
|
+
|
|
158
|
+
**When to Use:**
|
|
159
|
+
- After quota calculations
|
|
160
|
+
- Before large operations
|
|
161
|
+
- Displaying warnings
|
|
162
|
+
- Implementing throttling
|
|
163
|
+
|
|
164
|
+
## Quota Management Strategy
|
|
165
|
+
|
|
166
|
+
### Monitoring Quota
|
|
167
|
+
|
|
168
|
+
**Strategy:** Track quota usage throughout the day.
|
|
169
|
+
|
|
170
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/constants`
|
|
171
|
+
|
|
172
|
+
**When to Monitor:**
|
|
173
|
+
- After write operations
|
|
174
|
+
- After read operations
|
|
175
|
+
- Periodically (every hour)
|
|
176
|
+
- Before large batch operations
|
|
177
|
+
|
|
178
|
+
**Monitoring Approach:**
|
|
179
|
+
1. Count operations by type
|
|
180
|
+
2. Use calculateQuotaUsage()
|
|
181
|
+
3. Check thresholds
|
|
182
|
+
4. Warn if approaching limit
|
|
183
|
+
5. Throttle if critical
|
|
184
|
+
|
|
185
|
+
### Warning Strategy
|
|
186
|
+
|
|
187
|
+
**Strategy:** Warn users at appropriate thresholds.
|
|
188
|
+
|
|
189
|
+
**Warning Threshold (80%):**
|
|
190
|
+
- Inform user of usage
|
|
191
|
+
- Suggest quota conservation
|
|
192
|
+
- Show remaining quota
|
|
193
|
+
- Optional: upgrade prompt
|
|
194
|
+
|
|
195
|
+
**Critical Threshold (90%):**
|
|
196
|
+
- Strong warning
|
|
197
|
+
- Block non-essential operations
|
|
198
|
+
- Require confirmation for operations
|
|
199
|
+
- Strong upgrade suggestion
|
|
200
|
+
|
|
201
|
+
**Limit Reached (100%):**
|
|
202
|
+
- Block all operations
|
|
203
|
+
- Show upgrade prompt
|
|
204
|
+
- Provide clear guidance
|
|
205
|
+
- Offer upgrade option
|
|
206
|
+
|
|
207
|
+
### Quota Reset Times
|
|
208
|
+
|
|
209
|
+
**Reads and Writes:**
|
|
210
|
+
- Reset daily at midnight Pacific Time
|
|
211
|
+
- 50,000 reads per day
|
|
212
|
+
- 20,000 writes per day
|
|
213
|
+
|
|
214
|
+
**Deletes:**
|
|
215
|
+
- Reset monthly on billing date
|
|
216
|
+
- 20,000 deletes per month
|
|
217
|
+
- Different reset period than reads/writes
|
|
218
|
+
|
|
219
|
+
**Strategy:**
|
|
220
|
+
1. Track reset times
|
|
221
|
+
2. Display reset time to users
|
|
222
|
+
3. Plan operations accordingly
|
|
223
|
+
4. Consider time zones
|
|
224
|
+
|
|
225
|
+
## Common Mistakes to Avoid
|
|
226
|
+
|
|
227
|
+
1. ❌ Hardcoding quota values
|
|
228
|
+
- ✅ Use FREE_TIER_LIMITS constant
|
|
229
|
+
|
|
230
|
+
2. ❌ Not calculating quota correctly
|
|
231
|
+
- ✅ Use calculateQuotaUsage()
|
|
232
|
+
|
|
233
|
+
3. ❌ Ignoring monthly delete quota
|
|
234
|
+
- ✅ Remember deletes are monthly
|
|
235
|
+
|
|
236
|
+
4. ❌ Not warning at thresholds
|
|
237
|
+
- ✅ Use isQuotaThresholdReached()
|
|
238
|
+
|
|
239
|
+
5. ❌ Mixing daily and monthly quotas
|
|
240
|
+
- ✅ Track separately
|
|
241
|
+
|
|
242
|
+
## AI Agent Instructions
|
|
243
|
+
|
|
244
|
+
### When Calculating Quota
|
|
245
|
+
|
|
246
|
+
1. Collect operation counts (reads, writes, deletes)
|
|
247
|
+
2. Call calculateQuotaUsage()
|
|
248
|
+
3. Check returned percentages
|
|
249
|
+
4. Compare with thresholds
|
|
250
|
+
5. Display to user if needed
|
|
251
|
+
|
|
252
|
+
### When Checking Thresholds
|
|
253
|
+
|
|
254
|
+
1. Calculate quota usage first
|
|
255
|
+
2. Call isQuotaThresholdReached(metrics, 80) for warning
|
|
256
|
+
3. Call isQuotaThresholdReached(metrics, 90) for critical
|
|
257
|
+
4. Display appropriate warning
|
|
258
|
+
5. Throttle operations if critical
|
|
259
|
+
|
|
260
|
+
### When Displaying Quota Info
|
|
261
|
+
|
|
262
|
+
1. Calculate current usage
|
|
263
|
+
2. Show used/limit for each type
|
|
264
|
+
3. Show percentage used
|
|
265
|
+
4. Display reset time
|
|
266
|
+
5. Suggest upgrade if near limit
|
|
267
|
+
|
|
268
|
+
## Code Quality Standards
|
|
269
|
+
|
|
270
|
+
### Constants
|
|
271
|
+
|
|
272
|
+
- Export all constants
|
|
273
|
+
- Use descriptive names
|
|
274
|
+
- Document reset periods
|
|
275
|
+
- Group related constants
|
|
276
|
+
- No magic numbers
|
|
277
|
+
|
|
278
|
+
### Utility Functions
|
|
279
|
+
|
|
280
|
+
- Type all parameters
|
|
281
|
+
- Type all returns
|
|
282
|
+
- Handle edge cases
|
|
283
|
+
- Document behavior
|
|
284
|
+
- Include examples in comments
|
|
285
|
+
|
|
286
|
+
## Performance Considerations
|
|
287
|
+
|
|
288
|
+
### Calculation Overhead
|
|
289
|
+
|
|
290
|
+
- Minimal overhead for calculations
|
|
291
|
+
- Simple arithmetic operations
|
|
292
|
+
- No network calls
|
|
293
|
+
- Safe for frequent use
|
|
294
|
+
- Cache results if needed
|
|
295
|
+
|
|
296
|
+
### Monitoring Frequency
|
|
297
|
+
|
|
298
|
+
- Don't calculate on every operation
|
|
299
|
+
- Calculate periodically (hourly)
|
|
300
|
+
- Calculate after batches
|
|
301
|
+
- Cache results
|
|
302
|
+
- Update UI efficiently
|
|
303
|
+
|
|
304
|
+
## Related Documentation
|
|
305
|
+
|
|
306
|
+
- [Firestore Module README](../../README.md)
|
|
307
|
+
- [Firestore Errors README](../errors/README.md)
|
|
308
|
+
- [Quota Error Detector README](../../utils/quota-error-detector/README.md)
|
|
309
|
+
- [Request Log Types README](../../entities/README.md)
|
|
310
|
+
|
|
311
|
+
## API Reference
|
|
312
|
+
|
|
313
|
+
### Constants
|
|
314
|
+
|
|
315
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/domain/constants`
|
|
316
|
+
|
|
317
|
+
| Constant | Type | Values |
|
|
318
|
+
|----------|------|--------|
|
|
319
|
+
| `FREE_TIER_LIMITS` | Object | { dailyReads: 50000, dailyWrites: 20000, monthlyDeletes: 20000 } |
|
|
320
|
+
| `QUOTA_THRESHOLDS` | Object | { warning: 80, critical: 90 } |
|
|
321
|
+
|
|
322
|
+
### Utility Functions
|
|
323
|
+
|
|
324
|
+
| Function | Parameters | Returns | Description |
|
|
325
|
+
|----------|-----------|---------|-------------|
|
|
326
|
+
| `calculateQuotaUsage` | `{ reads, writes, deletes }` | `QuotaMetrics` | Calculate usage percentages |
|
|
327
|
+
| `isQuotaThresholdReached` | `metrics, threshold` | `boolean` | Check if threshold reached |
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
**Last Updated:** 2025-01-08
|
|
332
|
+
**Maintainer:** Firestore Module Team
|