@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,370 @@
|
|
|
1
|
+
# Storage Deleter
|
|
2
|
+
|
|
3
|
+
Firebase Storage deletion functionality supporting single file and batch deletion operations.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides file deletion capabilities for Firebase Storage with single file deletion, batch deletion operations, URL/path parsing, and comprehensive error handling/reporting.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Storage Deleter
|
|
12
|
+
|
|
13
|
+
1. **ALWAYS** use deleter functions (never Firebase Storage SDK directly)
|
|
14
|
+
2. **TRACK** file paths in database for cleanup
|
|
15
|
+
3. **USE** batch deletion for multiple files
|
|
16
|
+
4. **HANDLE** deletion errors appropriately
|
|
17
|
+
5. **VERIFY** file paths before deletion
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Use deleter functions** - Import from storage module
|
|
22
|
+
2. **Track file paths** - Store paths in Firestore database
|
|
23
|
+
3. **Use batch deletion** - Delete multiple files efficiently
|
|
24
|
+
4. **Handle partial failures** - Some files may fail to delete
|
|
25
|
+
5. **Check deletion results** - Verify success/failure
|
|
26
|
+
6. **Clean up old files** - Remove unused files regularly
|
|
27
|
+
|
|
28
|
+
### Forbidden Practices
|
|
29
|
+
|
|
30
|
+
## ❌ NEVER
|
|
31
|
+
|
|
32
|
+
- Use Firebase Storage SDK directly in application code
|
|
33
|
+
- Delete files without tracking paths
|
|
34
|
+
- Ignore deletion failures
|
|
35
|
+
- Delete files based on URL patterns (unreliable)
|
|
36
|
+
- Assume deletion always succeeds
|
|
37
|
+
- Delete without user confirmation (for user-initiated actions)
|
|
38
|
+
|
|
39
|
+
## ⚠️ Avoid
|
|
40
|
+
|
|
41
|
+
- Sequential single deletes (use batch instead)
|
|
42
|
+
- Not tracking deleted files
|
|
43
|
+
- Deleting without verification
|
|
44
|
+
- Not cleaning up temporary files
|
|
45
|
+
- Ignoring partial batch failures
|
|
46
|
+
|
|
47
|
+
## Usage Strategies
|
|
48
|
+
|
|
49
|
+
### For Single File Deletion
|
|
50
|
+
|
|
51
|
+
**Strategy:** Use deleteStorageFile for individual file deletion.
|
|
52
|
+
|
|
53
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/deleter`
|
|
54
|
+
|
|
55
|
+
**When to Use:**
|
|
56
|
+
- Deleting single file (avatar, document)
|
|
57
|
+
- Replacing old file with new
|
|
58
|
+
- User-initiated deletion
|
|
59
|
+
- Temporary file cleanup
|
|
60
|
+
|
|
61
|
+
**Function:** `deleteStorageFile(downloadUrlOrPath)`
|
|
62
|
+
|
|
63
|
+
**Parameters:**
|
|
64
|
+
- `downloadUrlOrPath: string` - Download URL or storage path
|
|
65
|
+
|
|
66
|
+
**Returns:** `Promise<DeleteResult>`
|
|
67
|
+
- `success: boolean` - Deletion succeeded
|
|
68
|
+
- `storagePath: string` - Storage path
|
|
69
|
+
|
|
70
|
+
**Strategy:**
|
|
71
|
+
1. Use stored file path (from database)
|
|
72
|
+
2. Call deleteStorageFile
|
|
73
|
+
3. Check result.success
|
|
74
|
+
4. Handle failures appropriately
|
|
75
|
+
5. Update database to remove path reference
|
|
76
|
+
|
|
77
|
+
### For Batch Deletion
|
|
78
|
+
|
|
79
|
+
**Strategy:** Use deleteStorageFiles for multiple file deletion.
|
|
80
|
+
|
|
81
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/deleter`
|
|
82
|
+
|
|
83
|
+
**When to Use:**
|
|
84
|
+
- Deleting all user files
|
|
85
|
+
- Cleaning up multiple documents
|
|
86
|
+
- Gallery deletion
|
|
87
|
+
- Bulk file cleanup
|
|
88
|
+
|
|
89
|
+
**Function:** `deleteStorageFiles(urlsOrPaths)`
|
|
90
|
+
|
|
91
|
+
**Parameters:**
|
|
92
|
+
- `urlsOrPaths: string[]` - Array of download URLs or storage paths
|
|
93
|
+
|
|
94
|
+
**Returns:** `Promise<BatchDeleteResult>`
|
|
95
|
+
- `successful: string[]` - Array of deleted storage paths
|
|
96
|
+
- `failed: Array<{path, error}>` - Failed deletions with errors
|
|
97
|
+
|
|
98
|
+
**Strategy:**
|
|
99
|
+
1. Collect file paths from database
|
|
100
|
+
2. Call deleteStorageFiles with paths array
|
|
101
|
+
3. Check result.successful and result.failed
|
|
102
|
+
4. Log or retry failed deletions
|
|
103
|
+
5. Update database to remove deleted paths
|
|
104
|
+
|
|
105
|
+
### For User Account Deletion
|
|
106
|
+
|
|
107
|
+
**Strategy:** Delete all user files when account is deleted.
|
|
108
|
+
|
|
109
|
+
**Import From:** `@umituz/react-native-firebase/storage` and firestore
|
|
110
|
+
|
|
111
|
+
**When to Use:**
|
|
112
|
+
- User deletes account
|
|
113
|
+
- GDPR compliance
|
|
114
|
+
- User data cleanup
|
|
115
|
+
- Admin-initiated deletion
|
|
116
|
+
|
|
117
|
+
**Implementation Strategy:**
|
|
118
|
+
1. Fetch all user file paths from Firestore
|
|
119
|
+
2. Call deleteStorageFiles with paths
|
|
120
|
+
3. Check for partial failures
|
|
121
|
+
4. Log failed deletions for manual cleanup
|
|
122
|
+
5. Delete Firestore user document
|
|
123
|
+
6. Delete Auth account
|
|
124
|
+
|
|
125
|
+
### For Old Avatar Replacement
|
|
126
|
+
|
|
127
|
+
**Strategy:** Delete old avatar when uploading new one.
|
|
128
|
+
|
|
129
|
+
**Import From:** `@umituz/react-native-firebase/storage` and firestore
|
|
130
|
+
|
|
131
|
+
**When to Use:**
|
|
132
|
+
- User updates profile picture
|
|
133
|
+
- Avatar replacement
|
|
134
|
+
- Image updates
|
|
135
|
+
|
|
136
|
+
**Implementation Strategy:**
|
|
137
|
+
1. Upload new avatar
|
|
138
|
+
2. Get new download URL
|
|
139
|
+
3. Delete old avatar if path exists
|
|
140
|
+
4. Update user document with new path
|
|
141
|
+
5. Handle deletion failure gracefully (old file not critical)
|
|
142
|
+
|
|
143
|
+
### For Temporary File Cleanup
|
|
144
|
+
|
|
145
|
+
**Strategy:** Delete temporary files after use.
|
|
146
|
+
|
|
147
|
+
**Import From:** `@umituz/react-native-firebase/storage` and firestore
|
|
148
|
+
|
|
149
|
+
**When to Use:**
|
|
150
|
+
- Clean up temp files after processing
|
|
151
|
+
- Remove upload drafts
|
|
152
|
+
- Delete expired files
|
|
153
|
+
|
|
154
|
+
**Implementation Strategy:**
|
|
155
|
+
1. Track temporary files in database
|
|
156
|
+
2. Schedule cleanup after time period
|
|
157
|
+
3. Use batch deletion
|
|
158
|
+
4. Log failures for manual review
|
|
159
|
+
5. Update database to remove references
|
|
160
|
+
|
|
161
|
+
### For File Path Tracking
|
|
162
|
+
|
|
163
|
+
**Strategy:** Store file paths in Firestore for later deletion.
|
|
164
|
+
|
|
165
|
+
**Import From:** Firestore repository
|
|
166
|
+
|
|
167
|
+
**When to Use:**
|
|
168
|
+
- Need to delete files later
|
|
169
|
+
- User account management
|
|
170
|
+
- File ownership tracking
|
|
171
|
+
|
|
172
|
+
**Tracking Strategy:**
|
|
173
|
+
1. Store storagePath in document when uploading
|
|
174
|
+
2. Add to array field for multiple files
|
|
175
|
+
3. Use arrayUnion for adding paths
|
|
176
|
+
4. Use arrayRemove for removing paths
|
|
177
|
+
5. Query all paths when deleting
|
|
178
|
+
|
|
179
|
+
**Example Fields:**
|
|
180
|
+
- `avatarPath: string` - Single avatar path
|
|
181
|
+
- `photoPaths: string[]` - Multiple photo paths
|
|
182
|
+
- `temporaryPaths: string[]` - Temporary file paths
|
|
183
|
+
- `documentPaths: string[]` - Document file paths
|
|
184
|
+
|
|
185
|
+
### For Conditional Deletion
|
|
186
|
+
|
|
187
|
+
**Strategy:** Delete file only if not referenced elsewhere.
|
|
188
|
+
|
|
189
|
+
**Import From:** `@umituz/react-native-firebase/storage` and firestore
|
|
190
|
+
|
|
191
|
+
**When to Use:**
|
|
192
|
+
- File may be referenced by multiple documents
|
|
193
|
+
- Need to verify file not in use
|
|
194
|
+
- Prevent accidental deletion
|
|
195
|
+
|
|
196
|
+
**Implementation Strategy:**
|
|
197
|
+
1. Check if file path referenced in database
|
|
198
|
+
2. Only delete if not referenced
|
|
199
|
+
3. Use transactions for verification
|
|
200
|
+
4. Handle race conditions
|
|
201
|
+
5. Log skipped deletions
|
|
202
|
+
|
|
203
|
+
## Error Handling
|
|
204
|
+
|
|
205
|
+
### Batch Deletion Failures
|
|
206
|
+
|
|
207
|
+
**Strategy:** Handle partial failures in batch operations.
|
|
208
|
+
|
|
209
|
+
**Import From:** Handle BatchDeleteResult from deleteStorageFiles
|
|
210
|
+
|
|
211
|
+
**Failure Types:**
|
|
212
|
+
- File not found (non-critical)
|
|
213
|
+
- Network errors (retry recommended)
|
|
214
|
+
- Unauthorized access (critical)
|
|
215
|
+
- Storage quota exceeded (rare for deletion)
|
|
216
|
+
|
|
217
|
+
**Handling Strategy:**
|
|
218
|
+
1. Check result.failed array
|
|
219
|
+
2. Log failed deletions with errors
|
|
220
|
+
3. Retry network failures
|
|
221
|
+
4. Alert on unauthorized errors
|
|
222
|
+
5. Continue on file-not-found errors
|
|
223
|
+
|
|
224
|
+
### Retry Strategy
|
|
225
|
+
|
|
226
|
+
**Strategy:** Retry failed deletions with exponential backoff.
|
|
227
|
+
|
|
228
|
+
**Implementation:**
|
|
229
|
+
1. First attempt: deleteStorageFiles
|
|
230
|
+
2. Collect failed paths from result
|
|
231
|
+
3. Wait with exponential backoff (1s, 2s, 4s)
|
|
232
|
+
4. Retry only failed paths
|
|
233
|
+
5. Limit retries to 3 attempts
|
|
234
|
+
6. Log permanently failed paths
|
|
235
|
+
|
|
236
|
+
## Common Mistakes to Avoid
|
|
237
|
+
|
|
238
|
+
1. ❌ Not tracking file paths
|
|
239
|
+
- ✅ Store paths in Firestore database
|
|
240
|
+
|
|
241
|
+
2. ❌ Ignoring deletion failures
|
|
242
|
+
- ✅ Check result.success and handle failures
|
|
243
|
+
|
|
244
|
+
3. ❌ Deleting without user confirmation
|
|
245
|
+
- ✅ Confirm before destructive operations
|
|
246
|
+
|
|
247
|
+
4. ❌ Using sequential single deletes
|
|
248
|
+
- ✅ Use batch deletion for multiple files
|
|
249
|
+
|
|
250
|
+
5. ❌ Not cleaning up temporary files
|
|
251
|
+
- ✅ Schedule regular cleanup tasks
|
|
252
|
+
|
|
253
|
+
6. ❌ Assuming deletion always succeeds
|
|
254
|
+
- ✅ Verify and handle partial failures
|
|
255
|
+
|
|
256
|
+
## AI Agent Instructions
|
|
257
|
+
|
|
258
|
+
### When Deleting Single File
|
|
259
|
+
|
|
260
|
+
1. Retrieve file path from database
|
|
261
|
+
2. Call deleteStorageFile with path
|
|
262
|
+
3. Check result.success
|
|
263
|
+
4. Update database to remove path
|
|
264
|
+
5. Handle errors appropriately
|
|
265
|
+
|
|
266
|
+
### When Deleting Multiple Files
|
|
267
|
+
|
|
268
|
+
1. Collect all file paths from database
|
|
269
|
+
2. Call deleteStorageFiles with paths array
|
|
270
|
+
3. Check result.failed for partial failures
|
|
271
|
+
4. Retry failed deletions if appropriate
|
|
272
|
+
5. Update database to remove deleted paths
|
|
273
|
+
6. Log permanently failed deletions
|
|
274
|
+
|
|
275
|
+
### When Replacing File
|
|
276
|
+
|
|
277
|
+
1. Upload new file first
|
|
278
|
+
2. Get new download URL and path
|
|
279
|
+
3. Delete old file if path exists
|
|
280
|
+
4. Handle deletion failure gracefully
|
|
281
|
+
5. Update database with new path
|
|
282
|
+
|
|
283
|
+
### When Cleaning User Files
|
|
284
|
+
|
|
285
|
+
1. Query all user file paths from database
|
|
286
|
+
2. Use batch deletion
|
|
287
|
+
3. Check for partial failures
|
|
288
|
+
4. Log failures for manual cleanup
|
|
289
|
+
5. Delete user document
|
|
290
|
+
6. Delete Auth account
|
|
291
|
+
|
|
292
|
+
## Code Quality Standards
|
|
293
|
+
|
|
294
|
+
### TypeScript
|
|
295
|
+
|
|
296
|
+
- Use DeleteResult type for single deletion
|
|
297
|
+
- Use BatchDeleteResult for batch deletion
|
|
298
|
+
- Type all file path parameters
|
|
299
|
+
- Handle errors properly
|
|
300
|
+
|
|
301
|
+
### Error Handling
|
|
302
|
+
|
|
303
|
+
- Always check result.success
|
|
304
|
+
- Handle result.failed in batch operations
|
|
305
|
+
- Log technical errors for debugging
|
|
306
|
+
- Return user-friendly error messages
|
|
307
|
+
- Retry when appropriate
|
|
308
|
+
|
|
309
|
+
### File Path Management
|
|
310
|
+
|
|
311
|
+
- Store paths in Firestore database
|
|
312
|
+
- Use descriptive field names (avatarPath, photoPaths)
|
|
313
|
+
- Update paths on file operations
|
|
314
|
+
- Clean up path references on deletion
|
|
315
|
+
|
|
316
|
+
## Performance Considerations
|
|
317
|
+
|
|
318
|
+
### Batch vs Sequential
|
|
319
|
+
|
|
320
|
+
**Batch Deletion:**
|
|
321
|
+
- Deletes files in parallel
|
|
322
|
+
- Faster for multiple files
|
|
323
|
+
- Single API call
|
|
324
|
+
- Recommended for > 1 file
|
|
325
|
+
|
|
326
|
+
**Sequential Deletion:**
|
|
327
|
+
- Only use for single file
|
|
328
|
+
- Slower for multiple files
|
|
329
|
+
- Multiple API calls
|
|
330
|
+
- Not recommended
|
|
331
|
+
|
|
332
|
+
### Path Tracking Overhead
|
|
333
|
+
|
|
334
|
+
- Minimal overhead to store paths
|
|
335
|
+
- Faster deletion with known paths
|
|
336
|
+
- No need to list Storage files
|
|
337
|
+
- Better than URL parsing
|
|
338
|
+
|
|
339
|
+
## Related Documentation
|
|
340
|
+
|
|
341
|
+
- [Storage Module README](../README.md)
|
|
342
|
+
- [Storage Uploader README](../uploader/README.md)
|
|
343
|
+
- [Storage Types README](../types/README.md)
|
|
344
|
+
- [Auth README](../../auth/README.md)
|
|
345
|
+
|
|
346
|
+
## API Reference
|
|
347
|
+
|
|
348
|
+
### Main Functions
|
|
349
|
+
|
|
350
|
+
**Import Path:** `@umituz/react-native-firebase/storage` or `src/storage/deleter`
|
|
351
|
+
|
|
352
|
+
| Function | Parameters | Returns | Description |
|
|
353
|
+
|----------|-----------|---------|-------------|
|
|
354
|
+
| `deleteStorageFile` | downloadUrlOrPath | `Promise<DeleteResult>` | Delete single file |
|
|
355
|
+
| `deleteStorageFiles` | urlsOrPaths[] | `Promise<BatchDeleteResult>` | Delete multiple files |
|
|
356
|
+
|
|
357
|
+
### Type Definitions
|
|
358
|
+
|
|
359
|
+
**DeleteResult:**
|
|
360
|
+
- `success: boolean` - Deletion succeeded
|
|
361
|
+
- `storagePath: string` - Storage path
|
|
362
|
+
|
|
363
|
+
**BatchDeleteResult:**
|
|
364
|
+
- `successful: string[]` - Array of deleted storage paths
|
|
365
|
+
- `failed: Array<{path, error}>` - Failed deletions with error messages
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
**Last Updated:** 2025-01-08
|
|
370
|
+
**Maintainer:** Storage Module Team
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# Storage Types
|
|
2
|
+
|
|
3
|
+
TypeScript types and interfaces for Firebase Storage operations.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Provides TypeScript type definitions for Storage operations including upload results, upload options, delete results, and batch deletion results.
|
|
8
|
+
|
|
9
|
+
## For AI Agents
|
|
10
|
+
|
|
11
|
+
### Before Using Storage Types
|
|
12
|
+
|
|
13
|
+
1. **IMPORT** types from storage module for type safety
|
|
14
|
+
2. **USE** types for all Storage operation return values
|
|
15
|
+
3. **DEFINE** function parameters and return types
|
|
16
|
+
4. **NEVER** use `any` type for Storage operations
|
|
17
|
+
5. **CHECK** types with type guards when needed
|
|
18
|
+
|
|
19
|
+
### Required Practices
|
|
20
|
+
|
|
21
|
+
1. **Import types** from `@umituz/react-native-firebase/storage` or `src/storage/types`
|
|
22
|
+
2. **Type all functions** that interact with Storage
|
|
23
|
+
3. **Use type guards** for runtime type checking
|
|
24
|
+
4. **Define custom types** based on base types when needed
|
|
25
|
+
5. **Handle type unions** properly with discriminated unions
|
|
26
|
+
|
|
27
|
+
### Forbidden Practices
|
|
28
|
+
|
|
29
|
+
## ❌ NEVER
|
|
30
|
+
|
|
31
|
+
- Use `any` type for Storage operations
|
|
32
|
+
- Ignore TypeScript type errors
|
|
33
|
+
- Skip typing function parameters
|
|
34
|
+
- Assume types without checking
|
|
35
|
+
- Mix incompatible types
|
|
36
|
+
|
|
37
|
+
## ⚠️ Avoid
|
|
38
|
+
|
|
39
|
+
- Overly complex type transformations
|
|
40
|
+
- Unnecessary type assertions
|
|
41
|
+
- Not using provided types
|
|
42
|
+
- Creating duplicate type definitions
|
|
43
|
+
|
|
44
|
+
## Type Definitions
|
|
45
|
+
|
|
46
|
+
### UploadResult
|
|
47
|
+
|
|
48
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/types`
|
|
49
|
+
|
|
50
|
+
**Purpose:** Result type for successful file uploads
|
|
51
|
+
|
|
52
|
+
**Properties:**
|
|
53
|
+
- `downloadUrl: string` - Public download URL
|
|
54
|
+
- `storagePath: string` - Internal storage path
|
|
55
|
+
|
|
56
|
+
**Usage:**
|
|
57
|
+
- Return type for uploadBase64Image()
|
|
58
|
+
- Return type for uploadFile()
|
|
59
|
+
- Type-safe access to upload results
|
|
60
|
+
|
|
61
|
+
**When to Use:**
|
|
62
|
+
- Typing upload function returns
|
|
63
|
+
- Processing upload results
|
|
64
|
+
- Storing upload metadata
|
|
65
|
+
|
|
66
|
+
### UploadOptions
|
|
67
|
+
|
|
68
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/types`
|
|
69
|
+
|
|
70
|
+
**Purpose:** Options for file uploads
|
|
71
|
+
|
|
72
|
+
**Properties:**
|
|
73
|
+
- `mimeType?: string` - Content type (auto-detected for base64)
|
|
74
|
+
- `customMetadata?: Record<string, string>` - Custom metadata
|
|
75
|
+
|
|
76
|
+
**Usage:**
|
|
77
|
+
- Pass to uploadBase64Image() as third parameter
|
|
78
|
+
- Pass to uploadFile() as third parameter
|
|
79
|
+
- Add tracking metadata to uploads
|
|
80
|
+
|
|
81
|
+
**When to Use:**
|
|
82
|
+
- Specifying MIME type explicitly
|
|
83
|
+
- Adding custom metadata to uploads
|
|
84
|
+
- Tracking upload information
|
|
85
|
+
|
|
86
|
+
**Common Metadata Fields:**
|
|
87
|
+
- `uploadedBy` - User ID
|
|
88
|
+
- `originalFileName` - Original file name
|
|
89
|
+
- `type` - File type/category
|
|
90
|
+
- `uploadedAt` - ISO timestamp
|
|
91
|
+
- `width` / `height` - Image dimensions
|
|
92
|
+
|
|
93
|
+
### DeleteResult
|
|
94
|
+
|
|
95
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/types`
|
|
96
|
+
|
|
97
|
+
**Purpose:** Result type for file deletion operations
|
|
98
|
+
|
|
99
|
+
**Properties:**
|
|
100
|
+
- `success: boolean` - Deletion succeeded
|
|
101
|
+
- `storagePath: string` - Storage path
|
|
102
|
+
|
|
103
|
+
**Usage:**
|
|
104
|
+
- Return type for deleteStorageFile()
|
|
105
|
+
- Check success status
|
|
106
|
+
- Access deleted file path
|
|
107
|
+
|
|
108
|
+
**When to Use:**
|
|
109
|
+
- Typing delete function returns
|
|
110
|
+
- Verifying deletion success
|
|
111
|
+
- Error handling
|
|
112
|
+
|
|
113
|
+
### BatchDeleteResult
|
|
114
|
+
|
|
115
|
+
**Import From:** `@umituz/react-native-firebase/storage` or `src/storage/types`
|
|
116
|
+
|
|
117
|
+
**Purpose:** Result type for batch file deletion operations
|
|
118
|
+
|
|
119
|
+
**Properties:**
|
|
120
|
+
- `successful: string[]` - Array of deleted storage paths
|
|
121
|
+
- `failed: Array<{path, error}>` - Array of failed deletions
|
|
122
|
+
|
|
123
|
+
**Usage:**
|
|
124
|
+
- Return type for deleteStorageFiles()
|
|
125
|
+
- Check partial failures
|
|
126
|
+
- Handle batch operations
|
|
127
|
+
|
|
128
|
+
**When to Use:**
|
|
129
|
+
- Typing batch delete returns
|
|
130
|
+
- Processing batch results
|
|
131
|
+
- Handling partial failures
|
|
132
|
+
|
|
133
|
+
## Type Guards
|
|
134
|
+
|
|
135
|
+
### isUploadResult
|
|
136
|
+
|
|
137
|
+
**Import From:** Create in your codebase or import from utils
|
|
138
|
+
|
|
139
|
+
**Purpose:** Check if value is UploadResult
|
|
140
|
+
|
|
141
|
+
**Returns:** `boolean`
|
|
142
|
+
|
|
143
|
+
**Usage Strategy:**
|
|
144
|
+
1. Check if value is object
|
|
145
|
+
2. Check for downloadUrl property
|
|
146
|
+
3. Check for storagePath property
|
|
147
|
+
4. Verify types are strings
|
|
148
|
+
5. Return boolean
|
|
149
|
+
|
|
150
|
+
### isSuccessfulDelete
|
|
151
|
+
|
|
152
|
+
**Import From:** Create in your codebase or import from utils
|
|
153
|
+
|
|
154
|
+
**Purpose:** Check if DeleteResult is successful
|
|
155
|
+
|
|
156
|
+
**Returns:** `boolean`
|
|
157
|
+
|
|
158
|
+
**Usage Strategy:**
|
|
159
|
+
1. Check result.success property
|
|
160
|
+
2. Return boolean
|
|
161
|
+
3. Use for conditional logic
|
|
162
|
+
|
|
163
|
+
### hasFailures
|
|
164
|
+
|
|
165
|
+
**Import From:** Create in your codebase or import from utils
|
|
166
|
+
|
|
167
|
+
**Purpose:** Check if BatchDeleteResult has failures
|
|
168
|
+
|
|
169
|
+
**Returns:** `boolean`
|
|
170
|
+
|
|
171
|
+
**Usage Strategy:**
|
|
172
|
+
1. Check result.failed.length > 0
|
|
173
|
+
2. Return boolean
|
|
174
|
+
3. Use for error handling
|
|
175
|
+
|
|
176
|
+
## Type Utilities
|
|
177
|
+
|
|
178
|
+
### Utility Types
|
|
179
|
+
|
|
180
|
+
**Import From:** Use with base types from storage
|
|
181
|
+
|
|
182
|
+
**Purpose:** Create derived types from base types
|
|
183
|
+
|
|
184
|
+
**Common Utilities:**
|
|
185
|
+
- `UploadResults` - Array of UploadResult
|
|
186
|
+
- `DeleteResults` - Array of DeleteResult
|
|
187
|
+
- `UploadResultMap` - Record<string, UploadResult>
|
|
188
|
+
- `DeleteResultMap` - Record<string, DeleteResult>
|
|
189
|
+
- `UploadPromise` - Promise<UploadResult>
|
|
190
|
+
- `DeletePromise` - Promise<DeleteResult>
|
|
191
|
+
- `BatchDeletePromise` - Promise<BatchDeleteResult>
|
|
192
|
+
|
|
193
|
+
**Usage:**
|
|
194
|
+
- Type arrays of results
|
|
195
|
+
- Type promises of results
|
|
196
|
+
- Type mapped result objects
|
|
197
|
+
- Create generic type-safe functions
|
|
198
|
+
|
|
199
|
+
### Extract Types
|
|
200
|
+
|
|
201
|
+
**Import From:** Use TypeScript utility types
|
|
202
|
+
|
|
203
|
+
**Purpose:** Extract specific property types
|
|
204
|
+
|
|
205
|
+
**Examples:**
|
|
206
|
+
- `type DownloadURL = UploadResult['downloadUrl']`
|
|
207
|
+
- `type StoragePath = UploadResult['storagePath']`
|
|
208
|
+
|
|
209
|
+
**Usage:**
|
|
210
|
+
- Type specific properties
|
|
211
|
+
- Create utility functions
|
|
212
|
+
- Enforce type consistency
|
|
213
|
+
|
|
214
|
+
## Common Mistakes to Avoid
|
|
215
|
+
|
|
216
|
+
1. ❌ Not typing upload results
|
|
217
|
+
- ✅ Always use UploadResult type
|
|
218
|
+
|
|
219
|
+
2. ❌ Not checking delete success
|
|
220
|
+
- ✅ Check result.success property
|
|
221
|
+
|
|
222
|
+
3. ❌ Ignoring batch delete failures
|
|
223
|
+
- ✅ Check result.failed array
|
|
224
|
+
|
|
225
|
+
4. ❌ Using any type
|
|
226
|
+
- ✅ Use specific types
|
|
227
|
+
|
|
228
|
+
5. ❌ Not using provided types
|
|
229
|
+
- ✅ Import types from storage module
|
|
230
|
+
|
|
231
|
+
## AI Agent Instructions
|
|
232
|
+
|
|
233
|
+
### When Typing Upload Functions
|
|
234
|
+
|
|
235
|
+
1. Import UploadResult and UploadOptions
|
|
236
|
+
2. Type return value as Promise<UploadResult>
|
|
237
|
+
3. Type options parameter as UploadOptions
|
|
238
|
+
4. Use type guards for validation
|
|
239
|
+
5. Handle errors appropriately
|
|
240
|
+
|
|
241
|
+
### When Typing Delete Functions
|
|
242
|
+
|
|
243
|
+
1. Import DeleteResult or BatchDeleteResult
|
|
244
|
+
2. Type return value appropriately
|
|
245
|
+
3. Check result.success for single delete
|
|
246
|
+
4. Check result.failed for batch delete
|
|
247
|
+
5. Handle partial failures
|
|
248
|
+
|
|
249
|
+
### When Creating Custom Types
|
|
250
|
+
|
|
251
|
+
1. Import base types from storage
|
|
252
|
+
2. Extend or use utility types
|
|
253
|
+
3. Add specific properties
|
|
254
|
+
4. Maintain type compatibility
|
|
255
|
+
5. Export custom types
|
|
256
|
+
|
|
257
|
+
## Code Quality Standards
|
|
258
|
+
|
|
259
|
+
### TypeScript
|
|
260
|
+
|
|
261
|
+
- Always use provided types
|
|
262
|
+
- Never use `any` type
|
|
263
|
+
- Use type guards for runtime checks
|
|
264
|
+
- Prefer explicit types over inferred
|
|
265
|
+
- Export custom types
|
|
266
|
+
|
|
267
|
+
### Type Safety
|
|
268
|
+
|
|
269
|
+
- Enable strict mode
|
|
270
|
+
- Use noImplicitAny
|
|
271
|
+
- Enable strictNullChecks
|
|
272
|
+
- Use proper discriminated unions
|
|
273
|
+
- Avoid type assertions
|
|
274
|
+
|
|
275
|
+
## Performance Considerations
|
|
276
|
+
|
|
277
|
+
### Type Checking Overhead
|
|
278
|
+
|
|
279
|
+
- Zero runtime overhead
|
|
280
|
+
- Compile-time type checking only
|
|
281
|
+
- No performance impact
|
|
282
|
+
- Use type guards sparingly
|
|
283
|
+
|
|
284
|
+
### Type Inference
|
|
285
|
+
|
|
286
|
+
- Let TypeScript infer when possible
|
|
287
|
+
- Use explicit types for public APIs
|
|
288
|
+
- Type guards for runtime validation
|
|
289
|
+
- Keep type definitions simple
|
|
290
|
+
|
|
291
|
+
## Related Documentation
|
|
292
|
+
|
|
293
|
+
- [Storage Module README](../README.md)
|
|
294
|
+
- [Storage Uploader README](../uploader/README.md)
|
|
295
|
+
- [Storage Deleter README](../deleter/README.md)
|
|
296
|
+
|
|
297
|
+
## API Reference
|
|
298
|
+
|
|
299
|
+
### Main Types
|
|
300
|
+
|
|
301
|
+
**Import Path:** `@umituz/react-native-firebase/storage` or `src/storage/types`
|
|
302
|
+
|
|
303
|
+
| Type | Purpose | Properties |
|
|
304
|
+
|------|---------|------------|
|
|
305
|
+
| `UploadResult` | Upload operation result | downloadUrl, storagePath |
|
|
306
|
+
| `UploadOptions` | Upload configuration | mimeType?, customMetadata? |
|
|
307
|
+
| `DeleteResult` | Delete operation result | success, storagePath |
|
|
308
|
+
| `BatchDeleteResult` | Batch delete result | successful[], failed[] |
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
**Last Updated:** 2025-01-08
|
|
313
|
+
**Maintainer:** Storage Module Team
|