@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,239 @@
|
|
|
1
|
+
# Firestore Configuration
|
|
2
|
+
|
|
3
|
+
Firestore client initialization, configuration management, and service initialization.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides core Firestore client functionality including initialization, state management, service access, and error handling.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Firestore Config
|
|
12
|
+
|
|
13
|
+
1. **INITIALIZE** Firestore once at app startup
|
|
14
|
+
2. **CHECK** initialization status before use
|
|
15
|
+
3. **USE** getFirestore() to get Firestore instance
|
|
16
|
+
4. **HANDLE** initialization errors appropriately
|
|
17
|
+
5. **NEVER** initialize Firestore multiple times
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Initialize once** - Call initializeFirestore() at app startup
|
|
22
|
+
2. **Check status** - Verify initialization before using Firestore
|
|
23
|
+
3. **Get Firestore instance** - Use getFirestore() after initialization
|
|
24
|
+
4. **Handle errors** - Check for initialization errors
|
|
25
|
+
5. **Use repositories** - Use repository pattern instead of direct Firestore
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Initialize Firestore multiple times
|
|
32
|
+
- Use Firestore SDK before initialization
|
|
33
|
+
- Use getFirestore() from firebase/firestore directly
|
|
34
|
+
- Ignore initialization errors
|
|
35
|
+
- Skip initialization status check
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Initializing Firestore in components
|
|
40
|
+
- Not checking initialization status
|
|
41
|
+
- Direct Firestore SDK usage (use repositories)
|
|
42
|
+
- Initializing without Firebase app
|
|
43
|
+
- Not handling initialization failures
|
|
44
|
+
|
|
45
|
+
## Initialization Strategy
|
|
46
|
+
|
|
47
|
+
### Basic Initialization
|
|
48
|
+
|
|
49
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/config`
|
|
50
|
+
|
|
51
|
+
**Function:** `initializeFirestore()`
|
|
52
|
+
|
|
53
|
+
**Returns:** `Promise<void>`
|
|
54
|
+
|
|
55
|
+
**When to Use:**
|
|
56
|
+
- App startup (after Firebase initialized)
|
|
57
|
+
- Before any Firestore operations
|
|
58
|
+
- Root component initialization
|
|
59
|
+
|
|
60
|
+
**Initialization Flow:**
|
|
61
|
+
1. Verify Firebase app initialized
|
|
62
|
+
2. Get Firebase app instance
|
|
63
|
+
3. Initialize Firestore with app
|
|
64
|
+
4. Set initialization state
|
|
65
|
+
5. Handle errors appropriately
|
|
66
|
+
|
|
67
|
+
### Check Initialization Status
|
|
68
|
+
|
|
69
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/config`
|
|
70
|
+
|
|
71
|
+
**Functions:**
|
|
72
|
+
- `isFirestoreInitialized()` - Check if Firestore initialized
|
|
73
|
+
- `isFirestoreInitializing()` - Check if initializing
|
|
74
|
+
- `getFirestoreInitializationError()` - Get error if failed
|
|
75
|
+
|
|
76
|
+
**Returns:**
|
|
77
|
+
- `boolean` for status checks
|
|
78
|
+
- `Error | null` for error check
|
|
79
|
+
|
|
80
|
+
**When to Use:**
|
|
81
|
+
- Before Firestore operations
|
|
82
|
+
- Before using repositories
|
|
83
|
+
- Error recovery
|
|
84
|
+
- Status display
|
|
85
|
+
|
|
86
|
+
**Usage Strategy:**
|
|
87
|
+
1. Check isFirestoreInitialized()
|
|
88
|
+
2. If false, show loading or initialize
|
|
89
|
+
3. If error, show error message
|
|
90
|
+
4. Proceed with Firestore operations
|
|
91
|
+
|
|
92
|
+
## Service Access
|
|
93
|
+
|
|
94
|
+
### Get Firestore Instance
|
|
95
|
+
|
|
96
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/config`
|
|
97
|
+
|
|
98
|
+
**Function:** `getFirestore()`
|
|
99
|
+
|
|
100
|
+
**Returns:** `Firestore` instance from Firebase Firestore SDK
|
|
101
|
+
|
|
102
|
+
**Usage Strategy:**
|
|
103
|
+
1. Check initialization status first
|
|
104
|
+
2. Call getFirestore()
|
|
105
|
+
3. Use Firestore instance for operations
|
|
106
|
+
4. Handle errors appropriately
|
|
107
|
+
|
|
108
|
+
**When to Use:**
|
|
109
|
+
- Repository implementations
|
|
110
|
+
- Custom Firestore operations
|
|
111
|
+
- Direct Firestore SDK usage (rare)
|
|
112
|
+
- Advanced Firestore features
|
|
113
|
+
|
|
114
|
+
**Important:** Prefer using repositories over direct Firestore SDK usage
|
|
115
|
+
|
|
116
|
+
### Reset Client
|
|
117
|
+
|
|
118
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/config`
|
|
119
|
+
|
|
120
|
+
**Function:** `resetFirestoreClient()`
|
|
121
|
+
|
|
122
|
+
**Purpose:** Reset Firestore client state (useful for testing)
|
|
123
|
+
|
|
124
|
+
**When to Use:**
|
|
125
|
+
- Testing scenarios
|
|
126
|
+
- Error recovery
|
|
127
|
+
- Reinitialization
|
|
128
|
+
- Development
|
|
129
|
+
|
|
130
|
+
**Usage Strategy:**
|
|
131
|
+
1. Call resetFirestoreClient()
|
|
132
|
+
2. Reinitialize if needed
|
|
133
|
+
3. Use only in development/testing
|
|
134
|
+
4. Never use in production
|
|
135
|
+
|
|
136
|
+
## Common Mistakes to Avoid
|
|
137
|
+
|
|
138
|
+
1. ❌ Initializing Firestore multiple times
|
|
139
|
+
- ✅ Initialize once at app startup
|
|
140
|
+
|
|
141
|
+
2. ❌ Not checking initialization status
|
|
142
|
+
- ✅ Always check isFirestoreInitialized()
|
|
143
|
+
|
|
144
|
+
3. ❌ Using getFirestore() from firebase/firestore
|
|
145
|
+
- ✅ Use getFirestore() from firestore config
|
|
146
|
+
|
|
147
|
+
4. ❌ Initializing before Firebase app
|
|
148
|
+
- ✅ Initialize Firebase first, then Firestore
|
|
149
|
+
|
|
150
|
+
5. ❌ Ignoring initialization errors
|
|
151
|
+
- ✅ Handle and display errors
|
|
152
|
+
|
|
153
|
+
## AI Agent Instructions
|
|
154
|
+
|
|
155
|
+
### When Initializing Firestore
|
|
156
|
+
|
|
157
|
+
1. Initialize Firebase first
|
|
158
|
+
2. Call initializeFirestore()
|
|
159
|
+
3. Await initialization completion
|
|
160
|
+
4. Check for errors
|
|
161
|
+
5. Show error message if failed
|
|
162
|
+
|
|
163
|
+
### When Using Repositories
|
|
164
|
+
|
|
165
|
+
1. Check Firestore initialization status
|
|
166
|
+
2. If not initialized, initialize first
|
|
167
|
+
3. Use repositories for all operations
|
|
168
|
+
4. Handle errors appropriately
|
|
169
|
+
5. Show user feedback
|
|
170
|
+
|
|
171
|
+
### When Getting Firestore Instance
|
|
172
|
+
|
|
173
|
+
1. Check isFirestoreInitialized()
|
|
174
|
+
2. Call getFirestore()
|
|
175
|
+
3. Use Firestore instance
|
|
176
|
+
4. Handle uninitialized state
|
|
177
|
+
5. Prefer repositories over direct usage
|
|
178
|
+
|
|
179
|
+
## Code Quality Standards
|
|
180
|
+
|
|
181
|
+
### Initialization
|
|
182
|
+
|
|
183
|
+
- Initialize once at startup
|
|
184
|
+
- Check status before use
|
|
185
|
+
- Handle errors gracefully
|
|
186
|
+
- Show loading states
|
|
187
|
+
- Provide error feedback
|
|
188
|
+
|
|
189
|
+
### Error Handling
|
|
190
|
+
|
|
191
|
+
- Catch initialization errors
|
|
192
|
+
- Store error in state
|
|
193
|
+
- Provide error context
|
|
194
|
+
- Allow retry/recovery
|
|
195
|
+
- Log for debugging
|
|
196
|
+
|
|
197
|
+
## Performance Considerations
|
|
198
|
+
|
|
199
|
+
### Initialization Overhead
|
|
200
|
+
|
|
201
|
+
- One-time cost at app startup
|
|
202
|
+
- Async initialization (non-blocking)
|
|
203
|
+
- ~50-200ms typical
|
|
204
|
+
- Initialize once, reuse Firestore instance
|
|
205
|
+
- Don't reinitialize unnecessarily
|
|
206
|
+
|
|
207
|
+
### State Checking
|
|
208
|
+
|
|
209
|
+
- Fast boolean checks
|
|
210
|
+
- No performance overhead
|
|
211
|
+
- Safe to call frequently
|
|
212
|
+
- Use before Firestore operations
|
|
213
|
+
- Prevents errors
|
|
214
|
+
|
|
215
|
+
## Related Documentation
|
|
216
|
+
|
|
217
|
+
- [Firestore Module README](../../README.md)
|
|
218
|
+
- [Firestore Repositories README](../repositories/README.md)
|
|
219
|
+
- [Firebase Infrastructure Config README](../../../infrastructure/config/README.md)
|
|
220
|
+
|
|
221
|
+
## API Reference
|
|
222
|
+
|
|
223
|
+
### Main Functions
|
|
224
|
+
|
|
225
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/config`
|
|
226
|
+
|
|
227
|
+
| Function | Returns | Description |
|
|
228
|
+
|----------|---------|-------------|
|
|
229
|
+
| `initializeFirestore` | `Promise<void>` | Initialize Firestore |
|
|
230
|
+
| `getFirestore` | `Firestore` | Get Firestore instance |
|
|
231
|
+
| `isFirestoreInitialized` | `boolean` | Check if initialized |
|
|
232
|
+
| `isFirestoreInitializing` | `boolean` | Check if initializing |
|
|
233
|
+
| `getFirestoreInitializationError` | `Error \| null` | Get initialization error |
|
|
234
|
+
| `resetFirestoreClient` | `void` | Reset client state (testing) |
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
**Last Updated:** 2025-01-08
|
|
239
|
+
**Maintainer:** Firestore Module Team
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# Firestore Middleware
|
|
2
|
+
|
|
3
|
+
Middleware system for Firestore query operations providing request/response processing, quota tracking, and query deduplication.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides middleware system for intercepting and processing Firestore operations before and after execution, including query deduplication, quota tracking, and custom middleware support.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Middleware
|
|
12
|
+
|
|
13
|
+
1. **REGISTER** middleware in repository constructor
|
|
14
|
+
2. **IMPLEMENT** QueryMiddleware interface for custom middleware
|
|
15
|
+
3. **USE** built-in middleware when possible
|
|
16
|
+
4. **CONSIDER** performance impact
|
|
17
|
+
5. **ORDER** middleware correctly (execution order matters)
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Register middleware** - Add in repository constructor
|
|
22
|
+
2. **Order middleware** - Execution order matters
|
|
23
|
+
3. **Use built-in middleware** - Don't recreate existing functionality
|
|
24
|
+
4. **Keep middleware focused** - Single responsibility
|
|
25
|
+
5. **Handle errors** - Middleware should handle errors gracefully
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Register middleware after repository construction
|
|
32
|
+
- Mix unrelated concerns in one middleware
|
|
33
|
+
- Skip middleware in error cases
|
|
34
|
+
- Use middleware for business logic
|
|
35
|
+
- Block execution indefinitely
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Too much middleware (2-3 max per repository)
|
|
40
|
+
- Async operations in beforeQuery
|
|
41
|
+
- Complex logic in middleware
|
|
42
|
+
- Not handling errors
|
|
43
|
+
- Ignoring execution order
|
|
44
|
+
|
|
45
|
+
## Middleware Pattern
|
|
46
|
+
|
|
47
|
+
### QueryMiddleware Interface
|
|
48
|
+
|
|
49
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/middleware`
|
|
50
|
+
|
|
51
|
+
**Purpose:** Interface for all query middleware
|
|
52
|
+
|
|
53
|
+
**Methods:**
|
|
54
|
+
- `beforeQuery?(options)` - Process before query execution
|
|
55
|
+
- `afterQuery?(result, options)` - Process after query execution
|
|
56
|
+
|
|
57
|
+
**Usage:**
|
|
58
|
+
- Implement for custom middleware
|
|
59
|
+
- Register in repository constructor
|
|
60
|
+
- Process options before query
|
|
61
|
+
- Transform results after query
|
|
62
|
+
|
|
63
|
+
**Execution Order:**
|
|
64
|
+
1. All beforeQuery hooks (in registration order)
|
|
65
|
+
2. Query execution
|
|
66
|
+
3. All afterQuery hooks (in registration order)
|
|
67
|
+
|
|
68
|
+
## Built-in Middleware
|
|
69
|
+
|
|
70
|
+
### Query Deduplication Middleware
|
|
71
|
+
|
|
72
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/middleware`
|
|
73
|
+
|
|
74
|
+
**Purpose:** Prevent duplicate queries by caching results
|
|
75
|
+
|
|
76
|
+
**Import:** `queryDeduplicationMiddleware` or `QueryDeduplicationMiddleware` class
|
|
77
|
+
|
|
78
|
+
**Configuration Options:**
|
|
79
|
+
- `cacheTimeout?: number` - Cache duration in ms (default: 1000)
|
|
80
|
+
- `enableLogging?: boolean` - Enable debug logging (default: false)
|
|
81
|
+
|
|
82
|
+
**Strategy:**
|
|
83
|
+
1. First query executes and caches result
|
|
84
|
+
2. Identical query within timeout returns cached result
|
|
85
|
+
3. Uses query hash for comparison
|
|
86
|
+
4. Reduces Firestore quota usage
|
|
87
|
+
5. Improves performance
|
|
88
|
+
|
|
89
|
+
**When to Use:**
|
|
90
|
+
- Rapid duplicate queries
|
|
91
|
+
- Multiple components querying same data
|
|
92
|
+
- Reducing quota usage
|
|
93
|
+
- Performance optimization
|
|
94
|
+
|
|
95
|
+
**Benefits:**
|
|
96
|
+
- Prevents over-fetching
|
|
97
|
+
- Reduces quota usage
|
|
98
|
+
- Instant response for cached queries
|
|
99
|
+
- Optimistic UI support
|
|
100
|
+
|
|
101
|
+
**Custom Configuration:**
|
|
102
|
+
- Adjust cacheTimeout for your use case
|
|
103
|
+
- Enable logging in development
|
|
104
|
+
- Longer timeout = more caching but stale data risk
|
|
105
|
+
- Default 1 second balance
|
|
106
|
+
|
|
107
|
+
### Quota Tracking Middleware
|
|
108
|
+
|
|
109
|
+
**Import From:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/middleware`
|
|
110
|
+
|
|
111
|
+
**Purpose:** Track Firestore quota usage for all queries
|
|
112
|
+
|
|
113
|
+
**Import:** `quotaTrackingMiddleware`
|
|
114
|
+
|
|
115
|
+
**Tracks:**
|
|
116
|
+
- Read operations
|
|
117
|
+
- Write operations
|
|
118
|
+
- Delete operations
|
|
119
|
+
- Document counts per operation
|
|
120
|
+
|
|
121
|
+
**Strategy:**
|
|
122
|
+
1. Intercepts all repository operations
|
|
123
|
+
2. Counts affected documents
|
|
124
|
+
3. Tracks operation types
|
|
125
|
+
4. Logs quota usage
|
|
126
|
+
5. Can trigger warnings
|
|
127
|
+
|
|
128
|
+
**When to Use:**
|
|
129
|
+
- Monitoring quota usage
|
|
130
|
+
- Cost optimization
|
|
131
|
+
- Usage analytics
|
|
132
|
+
- Performance tracking
|
|
133
|
+
|
|
134
|
+
**Benefits:**
|
|
135
|
+
- Real-time quota tracking
|
|
136
|
+
- Cost awareness
|
|
137
|
+
- Usage optimization
|
|
138
|
+
- Warning system
|
|
139
|
+
|
|
140
|
+
## Custom Middleware
|
|
141
|
+
|
|
142
|
+
### Creating Custom Middleware
|
|
143
|
+
|
|
144
|
+
**Strategy:** Implement QueryMiddleware interface for custom behavior.
|
|
145
|
+
|
|
146
|
+
**Import From:** Extend QueryMiddleware from `src/firestore/infrastructure/middleware`
|
|
147
|
+
|
|
148
|
+
**When to Use:**
|
|
149
|
+
- Custom query logging
|
|
150
|
+
- Request modification
|
|
151
|
+
- Response transformation
|
|
152
|
+
- Error handling
|
|
153
|
+
- Analytics tracking
|
|
154
|
+
|
|
155
|
+
**Implementation:**
|
|
156
|
+
1. Implement QueryMiddleware interface
|
|
157
|
+
2. Add beforeQuery method (optional)
|
|
158
|
+
3. Add afterQuery method (optional)
|
|
159
|
+
4. Return modified options/results
|
|
160
|
+
5. Handle errors appropriately
|
|
161
|
+
|
|
162
|
+
**Use Cases:**
|
|
163
|
+
- Add query parameters globally
|
|
164
|
+
- Modify query options
|
|
165
|
+
- Transform results
|
|
166
|
+
- Log query details
|
|
167
|
+
- Track analytics
|
|
168
|
+
|
|
169
|
+
### Middleware Registration
|
|
170
|
+
|
|
171
|
+
**Strategy:** Register middleware in repository constructor.
|
|
172
|
+
|
|
173
|
+
**Import From:** Repository's registerMiddleware method
|
|
174
|
+
|
|
175
|
+
**When to Register:**
|
|
176
|
+
- Repository construction
|
|
177
|
+
- Before any queries
|
|
178
|
+
- In constructor only
|
|
179
|
+
|
|
180
|
+
**Registration Order:**
|
|
181
|
+
- Order matters for execution
|
|
182
|
+
- First registered = first executed
|
|
183
|
+
- Consider dependencies between middleware
|
|
184
|
+
- Deduplication usually first
|
|
185
|
+
- Quota tracking usually last
|
|
186
|
+
|
|
187
|
+
## Common Mistakes to Avoid
|
|
188
|
+
|
|
189
|
+
1. ❌ Registering middleware after construction
|
|
190
|
+
- ✅ Always register in constructor
|
|
191
|
+
|
|
192
|
+
2. ❌ Too much middleware
|
|
193
|
+
- ✅ Limit to 2-3 per repository
|
|
194
|
+
|
|
195
|
+
3. ❌ Complex logic in middleware
|
|
196
|
+
- ✅ Keep middleware focused
|
|
197
|
+
|
|
198
|
+
4. ❌ Not handling errors
|
|
199
|
+
- ✅ Handle errors gracefully
|
|
200
|
+
|
|
201
|
+
5. ❌ Ignoring execution order
|
|
202
|
+
- ✅ Order middleware correctly
|
|
203
|
+
|
|
204
|
+
## AI Agent Instructions
|
|
205
|
+
|
|
206
|
+
### When Using Built-in Middleware
|
|
207
|
+
|
|
208
|
+
1. Import from firestore module
|
|
209
|
+
2. Register in repository constructor
|
|
210
|
+
3. Configure if needed (timeout, logging)
|
|
211
|
+
4. Consider execution order
|
|
212
|
+
5. Test middleware behavior
|
|
213
|
+
|
|
214
|
+
### When Creating Custom Middleware
|
|
215
|
+
|
|
216
|
+
1. Implement QueryMiddleware interface
|
|
217
|
+
2. Keep it focused (single responsibility)
|
|
218
|
+
3. Handle both success and error cases
|
|
219
|
+
4. Return modified options/results
|
|
220
|
+
5. Document middleware behavior
|
|
221
|
+
|
|
222
|
+
### When Registering Middleware
|
|
223
|
+
|
|
224
|
+
1. Register in repository constructor
|
|
225
|
+
2. Order middleware correctly
|
|
226
|
+
3. Consider dependencies
|
|
227
|
+
4. Don't register too many
|
|
228
|
+
5. Test execution order
|
|
229
|
+
|
|
230
|
+
## Code Quality Standards
|
|
231
|
+
|
|
232
|
+
### TypeScript
|
|
233
|
+
|
|
234
|
+
- Implement QueryMiddleware interface
|
|
235
|
+
- Type all parameters and returns
|
|
236
|
+
- Handle errors with proper types
|
|
237
|
+
- Export middleware functions
|
|
238
|
+
- Document middleware behavior
|
|
239
|
+
|
|
240
|
+
### Performance
|
|
241
|
+
|
|
242
|
+
- Keep middleware lightweight
|
|
243
|
+
- Avoid async in beforeQuery
|
|
244
|
+
- Cache expensive operations
|
|
245
|
+
- Don't block execution
|
|
246
|
+
- Monitor overhead
|
|
247
|
+
|
|
248
|
+
### Testing
|
|
249
|
+
|
|
250
|
+
- Test middleware in isolation
|
|
251
|
+
- Test execution order
|
|
252
|
+
- Test error handling
|
|
253
|
+
- Test configuration options
|
|
254
|
+
- Test edge cases
|
|
255
|
+
|
|
256
|
+
## Performance Considerations
|
|
257
|
+
|
|
258
|
+
### Middleware Overhead
|
|
259
|
+
|
|
260
|
+
- Each middleware adds small overhead
|
|
261
|
+
- 2-3 middleware is acceptable
|
|
262
|
+
- More middleware = more overhead
|
|
263
|
+
- Profile performance in production
|
|
264
|
+
- Remove unused middleware
|
|
265
|
+
|
|
266
|
+
### Caching Strategy
|
|
267
|
+
|
|
268
|
+
**Query Deduplication:**
|
|
269
|
+
- Default 1 second cache
|
|
270
|
+
- Longer cache = more stale data risk
|
|
271
|
+
- Shorter cache = less benefit
|
|
272
|
+
- Adjust based on use case
|
|
273
|
+
- Monitor cache hit rate
|
|
274
|
+
|
|
275
|
+
### Quota Tracking
|
|
276
|
+
|
|
277
|
+
- Minimal overhead
|
|
278
|
+
- Counting operations only
|
|
279
|
+
- No network calls
|
|
280
|
+
- Safe for production
|
|
281
|
+
- Useful for optimization
|
|
282
|
+
|
|
283
|
+
## Related Documentation
|
|
284
|
+
|
|
285
|
+
- [Firestore Module README](../../README.md)
|
|
286
|
+
- [Repositories README](../repositories/README.md)
|
|
287
|
+
- [Quota Error Detector README](../../utils/quota-error-detector/README.md)
|
|
288
|
+
- [Request Log Types README](../../domain/entities/README.md)
|
|
289
|
+
|
|
290
|
+
## API Reference
|
|
291
|
+
|
|
292
|
+
### Built-in Middleware
|
|
293
|
+
|
|
294
|
+
**Import Path:** `@umituz/react-native-firebase/firestore` or `src/firestore/infrastructure/middleware`
|
|
295
|
+
|
|
296
|
+
| Middleware | Purpose | Configuration |
|
|
297
|
+
|-----------|---------|--------------|
|
|
298
|
+
| `queryDeduplicationMiddleware` | Cache duplicate queries | `cacheTimeout?, enableLogging?` |
|
|
299
|
+
| `quotaTrackingMiddleware` | Track quota usage | None (auto-configured) |
|
|
300
|
+
|
|
301
|
+
### QueryMiddleware Interface
|
|
302
|
+
|
|
303
|
+
**Interface Definition:**
|
|
304
|
+
|
|
305
|
+
QueryMiddleware interface with two optional methods:
|
|
306
|
+
- beforeQuery(options): Called before query execution
|
|
307
|
+
- afterQuery(result, options): Called after query execution
|
|
308
|
+
|
|
309
|
+
**Methods:**
|
|
310
|
+
- `beforeQuery` - Called before query execution
|
|
311
|
+
- `afterQuery` - Called after query execution
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
**Last Updated:** 2025-01-08
|
|
316
|
+
**Maintainer:** Firestore Module Team
|