@umituz/react-native-firebase 2.0.0 → 2.0.1
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/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,316 +0,0 @@
|
|
|
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
|