@umituz/react-native-firebase 2.0.0 → 2.0.2
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/package.json +1 -1
- package/src/domains/account-deletion/application/ports/reauthentication.types.ts +2 -0
- package/src/domains/auth/index.ts +0 -1
- package/src/domains/auth/domain/errors/README.md +0 -291
- package/src/domains/auth/infrastructure/config/README.md +0 -239
- package/src/domains/auth/infrastructure/services/README.md +0 -346
- package/src/domains/firestore/domain/README.md +0 -325
- package/src/domains/firestore/domain/constants/README.md +0 -332
- package/src/domains/firestore/domain/entities/README.md +0 -286
- package/src/domains/firestore/domain/errors/README.md +0 -389
- package/src/domains/firestore/infrastructure/config/README.md +0 -239
- package/src/domains/firestore/infrastructure/middleware/README.md +0 -316
- package/src/domains/firestore/infrastructure/repositories/README.md +0 -425
- package/src/domains/firestore/infrastructure/services/README.md +0 -332
- package/src/domains/firestore/types/pagination/README.md +0 -332
- package/src/domains/firestore/utils/README.md +0 -574
- package/src/domains/firestore/utils/dateUtils/README.md +0 -171
- package/src/domains/firestore/utils/document-mapper.helper/README.md +0 -309
- package/src/domains/firestore/utils/pagination.helper/README.md +0 -298
- package/src/domains/firestore/utils/query-builder/README.md +0 -291
- package/src/presentation/README.md +0 -556
- package/src/shared/domain/README.md +0 -628
- package/src/shared/infrastructure/README.md +0 -408
- package/src/shared/infrastructure/config/README.md +0 -262
|
@@ -1,332 +0,0 @@
|
|
|
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
|
|
@@ -1,286 +0,0 @@
|
|
|
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
|