@react-native-firebase/storage 24.1.0 → 25.0.0

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/{lib → dist/module}/StorageDownloadTask.js +4 -3
  3. package/dist/module/StorageDownloadTask.js.map +1 -0
  4. package/{lib → dist/module}/StorageListResult.js +13 -8
  5. package/dist/module/StorageListResult.js.map +1 -0
  6. package/dist/module/StorageReference.js +270 -0
  7. package/dist/module/StorageReference.js.map +1 -0
  8. package/{lib → dist/module}/StorageStatics.js +5 -16
  9. package/dist/module/StorageStatics.js.map +1 -0
  10. package/{lib → dist/module}/StorageTask.js +82 -71
  11. package/dist/module/StorageTask.js.map +1 -0
  12. package/{lib → dist/module}/StorageUploadTask.js +4 -3
  13. package/dist/module/StorageUploadTask.js.map +1 -0
  14. package/dist/module/index.js +29 -0
  15. package/dist/module/index.js.map +1 -0
  16. package/{lib/modular/index.js → dist/module/modular.js} +65 -79
  17. package/dist/module/modular.js.map +1 -0
  18. package/dist/module/namespaced.js +192 -0
  19. package/dist/module/namespaced.js.map +1 -0
  20. package/dist/module/package.json +1 -0
  21. package/dist/module/types/internal.js +4 -0
  22. package/dist/module/types/internal.js.map +1 -0
  23. package/dist/module/types/namespaced.js +64 -0
  24. package/dist/module/types/namespaced.js.map +1 -0
  25. package/dist/module/types/storage.js +139 -0
  26. package/dist/module/types/storage.js.map +1 -0
  27. package/dist/module/utils.js +105 -0
  28. package/dist/module/utils.js.map +1 -0
  29. package/dist/module/version.js +5 -0
  30. package/dist/module/version.js.map +1 -0
  31. package/dist/module/web/RNFBStorageModule.android.js +6 -0
  32. package/dist/module/web/RNFBStorageModule.android.js.map +1 -0
  33. package/dist/module/web/RNFBStorageModule.ios.js +6 -0
  34. package/dist/module/web/RNFBStorageModule.ios.js.map +1 -0
  35. package/{lib → dist/module}/web/RNFBStorageModule.js +115 -197
  36. package/dist/module/web/RNFBStorageModule.js.map +1 -0
  37. package/dist/typescript/lib/StorageDownloadTask.d.ts +6 -0
  38. package/dist/typescript/lib/StorageDownloadTask.d.ts.map +1 -0
  39. package/dist/typescript/lib/StorageListResult.d.ts +13 -0
  40. package/dist/typescript/lib/StorageListResult.d.ts.map +1 -0
  41. package/dist/typescript/lib/StorageReference.d.ts +87 -0
  42. package/dist/typescript/lib/StorageReference.d.ts.map +1 -0
  43. package/dist/typescript/lib/StorageStatics.d.ts +2 -0
  44. package/dist/typescript/lib/StorageStatics.d.ts.map +1 -0
  45. package/dist/typescript/lib/StorageTask.d.ts +43 -0
  46. package/dist/typescript/lib/StorageTask.d.ts.map +1 -0
  47. package/dist/typescript/lib/StorageUploadTask.d.ts +6 -0
  48. package/dist/typescript/lib/StorageUploadTask.d.ts.map +1 -0
  49. package/dist/typescript/lib/index.d.ts +6 -0
  50. package/dist/typescript/lib/index.d.ts.map +1 -0
  51. package/dist/typescript/lib/modular.d.ts +154 -0
  52. package/dist/typescript/lib/modular.d.ts.map +1 -0
  53. package/dist/typescript/lib/namespaced.d.ts +12 -0
  54. package/dist/typescript/lib/namespaced.d.ts.map +1 -0
  55. package/dist/typescript/lib/types/internal.d.ts +131 -0
  56. package/dist/typescript/lib/types/internal.d.ts.map +1 -0
  57. package/dist/typescript/lib/types/namespaced.d.ts +1122 -0
  58. package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
  59. package/dist/typescript/lib/types/storage.d.ts +338 -0
  60. package/dist/typescript/lib/types/storage.d.ts.map +1 -0
  61. package/dist/typescript/lib/utils.d.ts +20 -0
  62. package/dist/typescript/lib/utils.d.ts.map +1 -0
  63. package/dist/typescript/lib/version.d.ts +2 -0
  64. package/dist/typescript/lib/version.d.ts.map +1 -0
  65. package/dist/typescript/lib/web/RNFBStorageModule.android.d.ts +3 -0
  66. package/dist/typescript/lib/web/RNFBStorageModule.android.d.ts.map +1 -0
  67. package/dist/typescript/lib/web/RNFBStorageModule.d.ts +142 -0
  68. package/dist/typescript/lib/web/RNFBStorageModule.d.ts.map +1 -0
  69. package/dist/typescript/lib/web/RNFBStorageModule.ios.d.ts +3 -0
  70. package/dist/typescript/lib/web/RNFBStorageModule.ios.d.ts.map +1 -0
  71. package/dist/typescript/package.json +1 -0
  72. package/lib/StorageDownloadTask.ts +30 -0
  73. package/lib/StorageListResult.ts +61 -0
  74. package/lib/{StorageReference.js → StorageReference.ts} +103 -61
  75. package/lib/StorageStatics.ts +19 -0
  76. package/lib/StorageTask.ts +336 -0
  77. package/lib/StorageUploadTask.ts +30 -0
  78. package/lib/index.ts +27 -0
  79. package/lib/modular.ts +401 -0
  80. package/lib/{index.js → namespaced.ts} +70 -28
  81. package/lib/types/internal.ts +189 -0
  82. package/lib/{index.d.ts → types/namespaced.ts} +111 -49
  83. package/lib/types/storage.ts +417 -0
  84. package/lib/{utils.js → utils.ts} +62 -15
  85. package/lib/version.ts +2 -0
  86. package/lib/web/RNFBStorageModule.android.ts +3 -0
  87. package/lib/web/RNFBStorageModule.ios.ts +3 -0
  88. package/lib/web/RNFBStorageModule.ts +557 -0
  89. package/package.json +41 -7
  90. package/tsconfig.json +23 -0
  91. package/typedoc.json +1 -1
  92. package/lib/modular/index.d.ts +0 -276
  93. package/lib/version.js +0 -2
  94. package/lib/web/RNFBStorageModule.android.js +0 -2
  95. package/lib/web/RNFBStorageModule.ios.js +0 -2
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import StorageTask from './StorageTask';
19
+ import type { StorageReference, TaskSnapshot } from './types/storage';
20
+
21
+ const UPLOAD_TASK = 'upload';
22
+
23
+ export default class StorageUploadTask extends StorageTask {
24
+ constructor(
25
+ storageRef: StorageReference,
26
+ beginTaskFn: (task: StorageTask) => Promise<TaskSnapshot>,
27
+ ) {
28
+ super(UPLOAD_TASK, storageRef, beginTaskFn);
29
+ }
30
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ // Export modular types from types/storage
19
+ export type * from './types/storage';
20
+
21
+ // Export modular API functions
22
+ export * from './modular';
23
+
24
+ // Export namespaced API
25
+ export type { FirebaseStorageTypes } from './types/namespaced';
26
+ export * from './namespaced';
27
+ export { default } from './namespaced';
package/lib/modular.ts ADDED
@@ -0,0 +1,401 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { getApp } from '@react-native-firebase/app';
19
+ import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/dist/module/common';
20
+ import type { FirebaseApp } from '@react-native-firebase/app';
21
+ import type {
22
+ FirebaseStorage,
23
+ StorageReference,
24
+ FullMetadata,
25
+ ListResult,
26
+ ListOptions,
27
+ TaskResult,
28
+ Task,
29
+ SettableMetadata,
30
+ UploadMetadata,
31
+ EmulatorMockTokenOptions,
32
+ } from './types/storage';
33
+ import type { StorageReferenceInternal, StorageInternal } from './types/internal';
34
+
35
+ type WithModularDeprecationArg<F> = F extends (...args: infer P) => infer R
36
+ ? (...args: [...P, typeof MODULAR_DEPRECATION_ARG]) => R
37
+ : never;
38
+
39
+ function isUrl(path?: string): boolean {
40
+ if (typeof path !== 'string') {
41
+ return false;
42
+ }
43
+
44
+ return /^[A-Za-z]+:\/\//.test(decodeURIComponent(path));
45
+ }
46
+
47
+ /**
48
+ * Returns a Storage instance for the given app.
49
+ * @param app - FirebaseApp. Optional.
50
+ * @param bucketUrl - Storage bucket URL. Optional.
51
+ * @returns {Storage}
52
+ */
53
+ export function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage {
54
+ if (app) {
55
+ if (bucketUrl != null) {
56
+ return getApp(app.name).storage(bucketUrl);
57
+ }
58
+
59
+ return getApp(app.name).storage();
60
+ }
61
+
62
+ if (bucketUrl != null) {
63
+ return getApp().storage(bucketUrl);
64
+ }
65
+
66
+ return getApp().storage();
67
+ }
68
+
69
+ /**
70
+ * Modify this Storage instance to communicate with the Firebase Storage emulator.
71
+ * @param storage - Storage instance.
72
+ * @param host - emulator host (e.g. - 'localhost')
73
+ * @param port - emulator port (e.g. - 9199)
74
+ * @param options - `EmulatorMockTokenOptions` instance. Optional. Web only.
75
+ * @returns {void}
76
+ */
77
+ export function connectStorageEmulator(
78
+ storage: FirebaseStorage,
79
+ host: string,
80
+ port: number,
81
+ options?: EmulatorMockTokenOptions,
82
+ ): void {
83
+ return (
84
+ (storage as StorageInternal).useEmulator as WithModularDeprecationArg<
85
+ StorageInternal['useEmulator']
86
+ >
87
+ ).call(storage, host, port, options, MODULAR_DEPRECATION_ARG);
88
+ }
89
+
90
+ /**
91
+ * Returns a StorageReference for the given URL or path in the default bucket.
92
+ * @param storage - FirebaseStorage instance.
93
+ * @param url - Optional gs:// or https:// URL, or path. If empty, returns root reference.
94
+ * @returns {StorageReference}
95
+ */
96
+ export function ref(storage: FirebaseStorage, url?: string): StorageReference;
97
+ /**
98
+ * Returns a StorageReference for the given path, or the same reference if path is omitted.
99
+ * @param storageRef - StorageReference instance.
100
+ * @param path - Optional child path. If omitted, returns the same reference.
101
+ * @returns {StorageReference}
102
+ */
103
+ export function ref(storageRef: StorageReference, path?: string): StorageReference;
104
+ export function ref(
105
+ storageOrRef: FirebaseStorage | StorageReference,
106
+ path?: string,
107
+ ): StorageReference {
108
+ // ref(parentRef, path) → child reference; ref(parentRef) → same reference (firebase-js-sdk overload)
109
+ if (typeof (storageOrRef as StorageReference).fullPath === 'string') {
110
+ if (path === undefined) {
111
+ return storageOrRef as StorageReference;
112
+ }
113
+ return (
114
+ (storageOrRef as StorageReferenceInternal).child as WithModularDeprecationArg<
115
+ StorageReferenceInternal['child']
116
+ >
117
+ ).call(storageOrRef, path, MODULAR_DEPRECATION_ARG);
118
+ }
119
+
120
+ const storage = storageOrRef as FirebaseStorage;
121
+
122
+ if (path != null && isUrl(path)) {
123
+ return (
124
+ (storage as StorageInternal).refFromURL as WithModularDeprecationArg<
125
+ StorageInternal['refFromURL']
126
+ >
127
+ ).call(storage, path, MODULAR_DEPRECATION_ARG);
128
+ }
129
+ return (
130
+ (storage as StorageInternal).ref as WithModularDeprecationArg<StorageInternal['ref']>
131
+ ).call(storage, path, MODULAR_DEPRECATION_ARG);
132
+ }
133
+
134
+ /**
135
+ * Deletes the object at this reference's location.
136
+ * @param storageRef - Storage `Reference` instance.
137
+ * @returns {Promise<void>}
138
+ */
139
+ export function deleteObject(storageRef: StorageReference): Promise<void> {
140
+ return (
141
+ (storageRef as StorageReferenceInternal).delete as WithModularDeprecationArg<
142
+ StorageReferenceInternal['delete']
143
+ >
144
+ ).call(storageRef, MODULAR_DEPRECATION_ARG);
145
+ }
146
+
147
+ /**
148
+ * Downloads the data at the object's location. Returns an error if the object is not found.
149
+ * @param _storageRef - Storage `Reference` instance.
150
+ * @param _maxDownloadSizeBytes - The maximum allowed size in bytes to retrieve. Web only.
151
+ * @returns {Promise<Blob>}
152
+ */
153
+ export function getBlob(
154
+ _storageRef: StorageReference,
155
+ _maxDownloadSizeBytes?: number,
156
+ ): Promise<Blob> {
157
+ throw new Error('`getBlob()` is not implemented');
158
+ }
159
+
160
+ /**
161
+ * Downloads the data at the object's location. Returns an error if the object is not found.
162
+ * @param _storageRef - Storage `Reference` instance.
163
+ * @param _maxDownloadSizeBytes - The maximum allowed size in bytes to retrieve. Web only.
164
+ * @returns {Promise<ArrayBuffer>}
165
+ */
166
+ export function getBytes(
167
+ _storageRef: StorageReference,
168
+ _maxDownloadSizeBytes?: number,
169
+ ): Promise<ArrayBuffer> {
170
+ throw new Error('`getBytes()` is not implemented');
171
+ }
172
+
173
+ /**
174
+ * Deletes the object at this reference's location.
175
+ * @param storageRef - Storage `Reference` instance.
176
+ * @returns {Promise<string>}
177
+ */
178
+ export function getDownloadURL(storageRef: StorageReference): Promise<string> {
179
+ return (
180
+ (storageRef as StorageReferenceInternal).getDownloadURL as WithModularDeprecationArg<
181
+ StorageReferenceInternal['getDownloadURL']
182
+ >
183
+ ).call(storageRef, MODULAR_DEPRECATION_ARG);
184
+ }
185
+
186
+ /**
187
+ * Fetches metadata for the object at this location, if one exists.
188
+ * @param storageRef - Storage `Reference` instance.
189
+ * @returns {Promise<FullMetadata>}
190
+ */
191
+ export function getMetadata(storageRef: StorageReference): Promise<FullMetadata> {
192
+ return (
193
+ (storageRef as StorageReferenceInternal).getMetadata as WithModularDeprecationArg<
194
+ StorageReferenceInternal['getMetadata']
195
+ >
196
+ ).call(storageRef, MODULAR_DEPRECATION_ARG);
197
+ }
198
+
199
+ /**
200
+ * Downloads the data at the object's location. This API is only available in Nodejs.
201
+ * @param _storageRef - Storage `Reference` instance.
202
+ * @param _maxDownloadSizeBytes - The maximum allowed size in bytes to retrieve. Web only.
203
+ * @returns {NodeJS.ReadableStream;}
204
+ */
205
+ export function getStream(
206
+ _storageRef: StorageReference,
207
+ _maxDownloadSizeBytes?: number,
208
+ ): NodeJS.ReadableStream {
209
+ throw new Error('`getStream()` is not implemented');
210
+ }
211
+
212
+ /**
213
+ * List items (files) and prefixes (folders) under this storage reference
214
+ * @param storageRef - Storage `Reference` instance.
215
+ * @param options - Storage `ListOptions` instance. The options list() accepts.
216
+ * @returns {Promise<ListResult>}
217
+ */
218
+ export async function list(
219
+ storageRef: StorageReference,
220
+ options?: ListOptions,
221
+ ): Promise<ListResult> {
222
+ const result = await (
223
+ (storageRef as StorageReferenceInternal).list as WithModularDeprecationArg<
224
+ StorageReferenceInternal['list']
225
+ >
226
+ ).call(storageRef, options, MODULAR_DEPRECATION_ARG);
227
+
228
+ if (result.nextPageToken === null) {
229
+ delete result.nextPageToken;
230
+ }
231
+ return result;
232
+ }
233
+
234
+ /**
235
+ * List all items (files) and prefixes (folders) under this storage reference.
236
+ * @param storageRef - Storage `Reference` instance.
237
+ * @returns {Promise<ListResult>}
238
+ */
239
+ export async function listAll(storageRef: StorageReference): Promise<ListResult> {
240
+ const result = await (
241
+ (storageRef as StorageReferenceInternal).listAll as WithModularDeprecationArg<
242
+ StorageReferenceInternal['listAll']
243
+ >
244
+ ).call(storageRef, MODULAR_DEPRECATION_ARG);
245
+
246
+ if (result.nextPageToken === null) {
247
+ delete result.nextPageToken;
248
+ }
249
+ return result;
250
+ }
251
+
252
+ /**
253
+ * Updates the metadata for this object.
254
+ * @param storageRef - Storage `Reference` instance.
255
+ * @param metadata - A Storage `SettableMetadata` instance to update.
256
+ * @returns {Promise<FullMetadata>}
257
+ */
258
+ export function updateMetadata(
259
+ storageRef: StorageReference,
260
+ metadata: SettableMetadata,
261
+ ): Promise<FullMetadata> {
262
+ return (
263
+ (storageRef as StorageReferenceInternal).updateMetadata as WithModularDeprecationArg<
264
+ StorageReferenceInternal['updateMetadata']
265
+ >
266
+ ).call(storageRef, metadata, MODULAR_DEPRECATION_ARG);
267
+ }
268
+
269
+ /**
270
+ * Uploads data to this object's location. The upload is not resumable.
271
+ * @param _storageRef - Storage `Reference` instance.
272
+ * @param _data - The data (Blob | Uint8Array | ArrayBuffer) to upload to the storage bucket at the reference location.
273
+ * @param _metadata - A Storage `UploadMetadata` instance to update. Optional.
274
+ * @returns {Promise<TaskResult>}
275
+ */
276
+ export async function uploadBytes(
277
+ _storageRef: StorageReference,
278
+ _data: Blob | Uint8Array | ArrayBuffer,
279
+ _metadata?: UploadMetadata,
280
+ ): Promise<TaskResult> {
281
+ throw new Error('`uploadBytes()` is not implemented');
282
+ }
283
+
284
+ /**
285
+ * Uploads data to this object's location. The upload is not resumable.
286
+ * @param storageRef - Storage `Reference` instance.
287
+ * @param data - The data (Blob | Uint8Array | ArrayBuffer) to upload to the storage bucket at the reference location.
288
+ * @param metadata - A Storage `UploadMetadata` instance to update. Optional.
289
+ * @returns {Task}
290
+ */
291
+ export function uploadBytesResumable(
292
+ storageRef: StorageReference,
293
+ data: Blob | Uint8Array | ArrayBuffer,
294
+ metadata?: UploadMetadata,
295
+ ): Task {
296
+ return (
297
+ (storageRef as StorageReferenceInternal).put as WithModularDeprecationArg<
298
+ StorageReferenceInternal['put']
299
+ >
300
+ ).call(storageRef, data, metadata, MODULAR_DEPRECATION_ARG);
301
+ }
302
+
303
+ /**
304
+ * Uploads data to this object's location. The upload is not resumable.
305
+ * @param storageRef - Storage `Reference` instance.
306
+ * @param data - The string to upload.
307
+ * @param format - The format of the string to upload ('raw' | 'base64' | 'base64url' | 'data_url'). Optional.
308
+ * @param metadata - A Storage `UploadMetadata` instance to update. Optional.
309
+ * @returns {Task}
310
+ */
311
+ export function uploadString(
312
+ storageRef: StorageReference,
313
+ data: string,
314
+ format?: 'raw' | 'base64' | 'base64url' | 'data_url',
315
+ metadata?: UploadMetadata,
316
+ ): Task {
317
+ return (
318
+ (storageRef as StorageReferenceInternal).putString as WithModularDeprecationArg<
319
+ StorageReferenceInternal['putString']
320
+ >
321
+ ).call(storageRef, data, format, metadata, MODULAR_DEPRECATION_ARG);
322
+ }
323
+
324
+ // Methods not on the Firebase JS SDK below
325
+
326
+ /**
327
+ * Sets the maximum time in milliseconds to retry a download if a failure occurs.. android & iOS only.
328
+ * @param storage - Storage instance.
329
+ * @param time - The new maximum operation retry time in milliseconds.
330
+ * @returns {Promise<void>}
331
+ */
332
+ export function setMaxOperationRetryTime(storage: FirebaseStorage, time: number): Promise<void> {
333
+ return (
334
+ (storage as StorageInternal).setMaxOperationRetryTime as WithModularDeprecationArg<
335
+ StorageInternal['setMaxOperationRetryTime']
336
+ >
337
+ ).call(storage, time, MODULAR_DEPRECATION_ARG);
338
+ }
339
+
340
+ /**
341
+ * Sets the maximum time in milliseconds to retry an upload if a failure occurs. android & iOS only.
342
+ * @param storage - Storage instance.
343
+ * @param time - The new maximum operation retry time in milliseconds.
344
+ * @returns {Promise<void>}
345
+ */
346
+ export function setMaxUploadRetryTime(storage: FirebaseStorage, time: number): Promise<void> {
347
+ return (
348
+ (storage as StorageInternal).setMaxUploadRetryTime as WithModularDeprecationArg<
349
+ StorageInternal['setMaxUploadRetryTime']
350
+ >
351
+ ).call(storage, time, MODULAR_DEPRECATION_ARG);
352
+ }
353
+
354
+ /**
355
+ * Puts a file from local disk onto the storage bucket.
356
+ * @param storageRef - Storage Reference instance.
357
+ * @param filePath The local file path to upload to the bucket at the reference location.
358
+ * @param metadata Any additional `UploadMetadata` for this task.
359
+ * @returns {Task}
360
+ */
361
+ export function putFile(
362
+ storageRef: StorageReference,
363
+ filePath: string,
364
+ metadata?: UploadMetadata,
365
+ ): Task {
366
+ return (
367
+ (storageRef as StorageReferenceInternal).putFile as WithModularDeprecationArg<
368
+ StorageReferenceInternal['putFile']
369
+ >
370
+ ).call(storageRef, filePath, metadata, MODULAR_DEPRECATION_ARG);
371
+ }
372
+
373
+ /**
374
+ * Downloads a file to the specified local file path on the device.
375
+ * @param storageRef - Storage Reference instance.
376
+ * @param filePath The local file path to upload to on the device.
377
+ * @returns {Task}
378
+ */
379
+ export function writeToFile(storageRef: StorageReference, filePath: string): Task {
380
+ return (
381
+ (storageRef as StorageReferenceInternal).writeToFile as WithModularDeprecationArg<
382
+ StorageReferenceInternal['writeToFile']
383
+ >
384
+ ).call(storageRef, filePath, MODULAR_DEPRECATION_ARG);
385
+ }
386
+
387
+ /**
388
+ * Sets the maximum time in milliseconds to retry a download if a failure occurs.
389
+ * @param storage - Storage instance.
390
+ * @param time - The new maximum download retry time in milliseconds.
391
+ * @returns {Promise<void>}
392
+ */
393
+ export function setMaxDownloadRetryTime(storage: FirebaseStorage, time: number): Promise<void> {
394
+ return (
395
+ (storage as StorageInternal).setMaxDownloadRetryTime as WithModularDeprecationArg<
396
+ StorageInternal['setMaxDownloadRetryTime']
397
+ >
398
+ ).call(storage, time, MODULAR_DEPRECATION_ARG);
399
+ }
400
+
401
+ export { StringFormat, TaskEvent, TaskState } from './StorageStatics';
@@ -27,14 +27,17 @@ import {
27
27
  createModuleNamespace,
28
28
  FirebaseModule,
29
29
  getFirebaseRoot,
30
+ type ModuleConfig,
30
31
  } from '@react-native-firebase/app/dist/module/internal';
31
- import StorageReference from './StorageReference';
32
+ import type { ReactNativeFirebase } from '@react-native-firebase/app';
33
+ import Reference from './StorageReference';
32
34
  import { StringFormat, TaskEvent, TaskState } from './StorageStatics';
33
35
  import { getGsUrlParts, getHttpUrlParts, handleStorageEvent } from './utils';
34
- import version from './version';
36
+ import { version } from './version';
35
37
  import fallBackModule from './web/RNFBStorageModule';
38
+ import type { StorageInternal } from './types/internal';
39
+ import type { FirebaseStorageTypes } from './types/namespaced';
36
40
 
37
- // import { STATICS } from '@react-native-firebase/storage';
38
41
  const statics = {
39
42
  StringFormat,
40
43
  TaskEvent,
@@ -45,10 +48,20 @@ const namespace = 'storage';
45
48
  const nativeEvents = ['storage_event'];
46
49
  const nativeModuleName = 'RNFBStorageModule';
47
50
 
48
- class FirebaseStorageModule extends FirebaseModule {
49
- constructor(app, config, bucketUrl) {
50
- super(app, config, bucketUrl);
51
- if (bucketUrl === undefined) {
51
+ class FirebaseStorageModule extends FirebaseModule<typeof nativeModuleName> {
52
+ emulatorHost: string | undefined;
53
+ emulatorPort: number;
54
+ _maxUploadRetryTime: number;
55
+ _maxDownloadRetryTime: number;
56
+ _maxOperationRetryTime: number;
57
+
58
+ constructor(
59
+ app: ReactNativeFirebase.FirebaseAppBase,
60
+ config: ModuleConfig,
61
+ bucketUrl?: string | null,
62
+ ) {
63
+ super(app, config, bucketUrl ?? undefined);
64
+ if (bucketUrl == null) {
52
65
  this._customUrlOrRegion = `gs://${app.options.storageBucket}`;
53
66
  } else if (!isString(bucketUrl) || !bucketUrl.startsWith('gs://')) {
54
67
  throw new Error(
@@ -56,8 +69,14 @@ class FirebaseStorageModule extends FirebaseModule {
56
69
  );
57
70
  }
58
71
 
72
+ const storageEvent = nativeEvents[0];
73
+
74
+ if (!storageEvent) {
75
+ throw new Error('storage_event is not defined in nativeEvents');
76
+ }
77
+
59
78
  this.emitter.addListener(
60
- this.eventNameForApp(nativeEvents[0]),
79
+ this.eventNameForApp(storageEvent),
61
80
  handleStorageEvent.bind(null, this),
62
81
  );
63
82
 
@@ -72,46 +91,46 @@ class FirebaseStorageModule extends FirebaseModule {
72
91
  /**
73
92
  * @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setmaxuploadretrytime
74
93
  */
75
- get maxUploadRetryTime() {
94
+ get maxUploadRetryTime(): number {
76
95
  return this._maxUploadRetryTime;
77
96
  }
78
97
 
79
98
  /**
80
99
  * @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setmaxdownloadretrytime
81
100
  */
82
- get maxDownloadRetryTime() {
101
+ get maxDownloadRetryTime(): number {
83
102
  return this._maxDownloadRetryTime;
84
103
  }
85
104
 
86
105
  /**
87
106
  * @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#maxoperationretrytime
88
107
  */
89
- get maxOperationRetryTime() {
108
+ get maxOperationRetryTime(): number {
90
109
  return this._maxOperationRetryTime;
91
110
  }
92
111
 
93
112
  /**
94
113
  * @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#ref
95
114
  */
96
- ref(path = '/') {
115
+ ref(path: string = '/'): Reference {
97
116
  if (!isString(path)) {
98
117
  throw new Error("firebase.storage().ref(*) 'path' must be a string value.");
99
118
  }
100
- return createDeprecationProxy(new StorageReference(this, path));
119
+ return createDeprecationProxy(new Reference(this, path)) as Reference;
101
120
  }
102
121
 
103
122
  /**
104
123
  * @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#refFromURL
105
124
  */
106
- refFromURL(url) {
125
+ refFromURL(url: string): Reference {
107
126
  if (!isString(url) || (!url.startsWith('gs://') && !url.startsWith('http'))) {
108
127
  throw new Error(
109
128
  "firebase.storage().refFromURL(*) 'url' must be a string value and begin with 'gs://' or 'https://'.",
110
129
  );
111
130
  }
112
131
 
113
- let path;
114
- let bucket;
132
+ let path: string;
133
+ let bucket: string;
115
134
 
116
135
  if (url.startsWith('http')) {
117
136
  const parts = getHttpUrlParts(url);
@@ -126,13 +145,13 @@ class FirebaseStorageModule extends FirebaseModule {
126
145
  }
127
146
 
128
147
  const storageInstance = this.app.storage(bucket);
129
- return new StorageReference(storageInstance, path);
148
+ return new Reference(storageInstance as unknown as StorageInternal, path);
130
149
  }
131
150
 
132
151
  /**
133
152
  * @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setMaxOperationRetryTime
134
153
  */
135
- setMaxOperationRetryTime(time) {
154
+ setMaxOperationRetryTime(time: number): Promise<void> {
136
155
  if (!isNumber(time)) {
137
156
  throw new Error(
138
157
  "firebase.storage().setMaxOperationRetryTime(*) 'time' must be a number value.",
@@ -146,7 +165,7 @@ class FirebaseStorageModule extends FirebaseModule {
146
165
  /**
147
166
  * @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setMaxUploadRetryTime
148
167
  */
149
- setMaxUploadRetryTime(time) {
168
+ setMaxUploadRetryTime(time: number): Promise<void> {
150
169
  if (!isNumber(time)) {
151
170
  throw new Error("firebase.storage().setMaxUploadRetryTime(*) 'time' must be a number value.");
152
171
  }
@@ -158,7 +177,7 @@ class FirebaseStorageModule extends FirebaseModule {
158
177
  /**
159
178
  * @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setMaxDownloadRetryTime
160
179
  */
161
- setMaxDownloadRetryTime(time) {
180
+ setMaxDownloadRetryTime(time: number): Promise<void> {
162
181
  if (!isNumber(time)) {
163
182
  throw new Error(
164
183
  "firebase.storage().setMaxDownloadRetryTime(*) 'time' must be a number value.",
@@ -169,7 +188,11 @@ class FirebaseStorageModule extends FirebaseModule {
169
188
  return this.native.setMaxDownloadRetryTime(time);
170
189
  }
171
190
 
172
- useEmulator(host, port) {
191
+ useEmulator(
192
+ host: string,
193
+ port: number,
194
+ _options?: FirebaseStorageTypes.EmulatorMockTokenOptions,
195
+ ): void {
173
196
  if (!host || !isString(host) || !port || !isNumber(port)) {
174
197
  throw new Error('firebase.storage().useEmulator() takes a non-empty host and port');
175
198
  }
@@ -191,16 +214,15 @@ class FirebaseStorageModule extends FirebaseModule {
191
214
  this.emulatorHost = host;
192
215
  this.emulatorPort = port;
193
216
  this.native.useEmulator(_host, port, this._customUrlOrRegion);
194
- return [_host, port]; // undocumented return, just used to unit test android host remapping
217
+ // @ts-ignore undocumented return, just used to unit test android host remapping
218
+ return [_host, port];
195
219
  }
196
220
  }
197
221
 
198
222
  // import { SDK_VERSION } from '@react-native-firebase/storage';
199
223
  export const SDK_VERSION = version;
200
224
 
201
- // import storage from '@react-native-firebase/storage';
202
- // storage().X(...);
203
- export default createModuleNamespace({
225
+ const storageNamespace = createModuleNamespace({
204
226
  statics,
205
227
  version,
206
228
  namespace,
@@ -212,11 +234,31 @@ export default createModuleNamespace({
212
234
  ModuleClass: FirebaseStorageModule,
213
235
  });
214
236
 
237
+ type StorageNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
238
+ FirebaseStorageTypes.Module,
239
+ FirebaseStorageTypes.Statics
240
+ > & {
241
+ storage: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
242
+ FirebaseStorageTypes.Module,
243
+ FirebaseStorageTypes.Statics
244
+ >;
245
+ firebase: ReactNativeFirebase.Module;
246
+ app(name?: string): ReactNativeFirebase.FirebaseApp;
247
+ };
248
+
249
+ // import storage from '@react-native-firebase/storage';
250
+ // storage().X(...);
251
+ export default storageNamespace as unknown as StorageNamespace;
252
+
215
253
  // import storage, { firebase } from '@react-native-firebase/storage';
216
254
  // storage().X(...);
217
255
  // firebase.storage().X(...);
218
- export const firebase = getFirebaseRoot();
219
-
220
- export * from './modular';
256
+ export const firebase =
257
+ getFirebaseRoot() as unknown as ReactNativeFirebase.FirebaseNamespacedExport<
258
+ 'storage',
259
+ FirebaseStorageTypes.Module,
260
+ FirebaseStorageTypes.Statics,
261
+ true
262
+ >;
221
263
 
222
264
  setReactNativeModule(nativeModuleName, fallBackModule);