@react-native-firebase/storage 25.1.0 → 26.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.
- package/CHANGELOG.md +21 -0
- package/RNFBStorage.podspec +17 -6
- package/android/build.gradle +23 -0
- package/android/src/main/java/io/invertase/firebase/storage/{ReactNativeFirebaseStorageModule.java → NativeRNFBTurboStorage.java} +72 -131
- package/android/src/main/java/io/invertase/firebase/storage/ReactNativeFirebaseStoragePackage.java +1 -1
- package/android/src/main/java/io/invertase/firebase/storage/generated/java/com/facebook/fbreact/specs/NativeRNFBTurboStorageSpec.java +125 -0
- package/android/src/main/java/io/invertase/firebase/storage/generated/jni/CMakeLists.txt +36 -0
- package/android/src/main/java/io/invertase/firebase/storage/generated/jni/RNFBStorageTurboModules-generated.cpp +116 -0
- package/android/src/main/java/io/invertase/firebase/storage/generated/jni/RNFBStorageTurboModules.h +31 -0
- package/android/src/main/java/io/invertase/firebase/storage/generated/jni/react/renderer/components/RNFBStorageTurboModules/RNFBStorageTurboModulesJSI-generated.cpp +153 -0
- package/android/src/main/java/io/invertase/firebase/storage/generated/jni/react/renderer/components/RNFBStorageTurboModules/RNFBStorageTurboModulesJSI.h +246 -0
- package/dist/module/StorageReference.js +4 -7
- package/dist/module/StorageReference.js.map +1 -1
- package/dist/module/StorageTask.js.map +1 -1
- package/dist/module/index.js +384 -6
- package/dist/module/index.js.map +1 -1
- package/dist/module/types/storage.js +6 -2
- package/dist/module/types/storage.js.map +1 -1
- package/dist/module/version.js +1 -1
- package/dist/module/web/RNFBStorageModule.js +9 -11
- package/dist/module/web/RNFBStorageModule.js.map +1 -1
- package/dist/typescript/lib/StorageReference.d.ts.map +1 -1
- package/dist/typescript/lib/StorageTask.d.ts +7 -8
- package/dist/typescript/lib/StorageTask.d.ts.map +1 -1
- package/dist/typescript/lib/index.d.ts +150 -4
- package/dist/typescript/lib/index.d.ts.map +1 -1
- package/dist/typescript/lib/types/internal.d.ts +5 -5
- package/dist/typescript/lib/types/internal.d.ts.map +1 -1
- package/dist/typescript/lib/types/storage.d.ts +15 -10
- package/dist/typescript/lib/types/storage.d.ts.map +1 -1
- package/dist/typescript/lib/version.d.ts +1 -1
- package/dist/typescript/lib/web/RNFBStorageModule.d.ts +3 -3
- package/dist/typescript/lib/web/RNFBStorageModule.d.ts.map +1 -1
- package/ios/RNFBStorage/RNFBStorageModule.h +2 -2
- package/ios/RNFBStorage/{RNFBStorageModule.m → RNFBStorageModule.mm} +193 -130
- package/ios/RNFBStorage.xcodeproj/project.pbxproj +8 -8
- package/ios/generated/RCTAppDependencyProvider.h +25 -0
- package/ios/generated/RCTAppDependencyProvider.mm +55 -0
- package/ios/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
- package/ios/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
- package/ios/generated/RCTThirdPartyComponentsProvider.h +16 -0
- package/ios/generated/RCTThirdPartyComponentsProvider.mm +23 -0
- package/ios/generated/RNFBStorageTurboModules/RNFBStorageTurboModules-generated.mm +142 -0
- package/ios/generated/RNFBStorageTurboModules/RNFBStorageTurboModules.h +198 -0
- package/ios/generated/RNFBStorageTurboModulesJSI-generated.cpp +153 -0
- package/ios/generated/RNFBStorageTurboModulesJSI.h +246 -0
- package/ios/generated/ReactAppDependencyProvider.podspec +34 -0
- package/lib/StorageReference.ts +3 -8
- package/lib/StorageTask.ts +13 -15
- package/lib/index.ts +501 -7
- package/lib/types/internal.ts +5 -5
- package/lib/types/storage.ts +17 -10
- package/lib/version.ts +1 -1
- package/lib/web/RNFBStorageModule.ts +10 -12
- package/package.json +22 -4
- package/react-native.config.js +10 -0
- package/specs/NativeRNFBTurboStorage.ts +46 -0
- package/typedoc.json +2 -3
- package/dist/module/modular.js +0 -270
- package/dist/module/modular.js.map +0 -1
- package/dist/module/namespaced.js +0 -192
- package/dist/module/namespaced.js.map +0 -1
- package/dist/module/types/namespaced.js +0 -64
- package/dist/module/types/namespaced.js.map +0 -1
- package/dist/typescript/lib/modular.d.ts +0 -154
- package/dist/typescript/lib/modular.d.ts.map +0 -1
- package/dist/typescript/lib/namespaced.d.ts +0 -12
- package/dist/typescript/lib/namespaced.d.ts.map +0 -1
- package/dist/typescript/lib/types/namespaced.d.ts +0 -1122
- package/dist/typescript/lib/types/namespaced.d.ts.map +0 -1
- package/lib/modular.ts +0 -401
- package/lib/namespaced.ts +0 -264
- package/lib/types/namespaced.ts +0 -1248
package/lib/index.ts
CHANGED
|
@@ -15,13 +15,507 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
import { isAndroid, isNumber, isString } from '@react-native-firebase/app/dist/module/common';
|
|
19
|
+
import type { FirebaseApp } from '@react-native-firebase/app';
|
|
20
|
+
import {
|
|
21
|
+
FirebaseModule,
|
|
22
|
+
getOrCreateModularInstance,
|
|
23
|
+
} from '@react-native-firebase/app/dist/module/internal';
|
|
24
|
+
import type { ModuleConfig } from '@react-native-firebase/app/dist/module/internal';
|
|
25
|
+
import type { ReactNativeFirebase } from '@react-native-firebase/app';
|
|
26
|
+
import Reference from './StorageReference';
|
|
27
|
+
import { getGsUrlParts, getHttpUrlParts, handleStorageEvent } from './utils';
|
|
28
|
+
import { version } from './version';
|
|
29
|
+
import fallBackModule from './web/RNFBStorageModule';
|
|
30
|
+
import { setReactNativeModule } from '@react-native-firebase/app/dist/module/internal/nativeModule';
|
|
31
|
+
import './types/internal';
|
|
32
|
+
import type {
|
|
33
|
+
EmulatorMockTokenOptions,
|
|
34
|
+
FirebaseStorage,
|
|
35
|
+
FullMetadata,
|
|
36
|
+
ListOptions,
|
|
37
|
+
ListResult,
|
|
38
|
+
SettableMetadata,
|
|
39
|
+
StorageReference,
|
|
40
|
+
Task,
|
|
41
|
+
UploadMetadata,
|
|
42
|
+
UploadResult,
|
|
43
|
+
UploadTask,
|
|
44
|
+
} from './types/storage';
|
|
45
|
+
import type { StorageInternal, StorageReferenceInternal } from './types/internal';
|
|
46
|
+
|
|
47
|
+
const nativeEvents = ['storage_event'];
|
|
48
|
+
const nativeModuleName = 'NativeRNFBTurboStorage';
|
|
49
|
+
|
|
50
|
+
const config: ModuleConfig = {
|
|
51
|
+
namespace: 'storage',
|
|
52
|
+
nativeEvents,
|
|
53
|
+
nativeModuleName,
|
|
54
|
+
hasMultiAppSupport: true,
|
|
55
|
+
hasCustomUrlOrRegionSupport: true,
|
|
56
|
+
disablePrependCustomUrlOrRegion: true,
|
|
57
|
+
turboModule: true,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
class FirebaseStorageModule extends FirebaseModule<typeof nativeModuleName> {
|
|
61
|
+
emulatorHost: string | undefined;
|
|
62
|
+
emulatorPort: number;
|
|
63
|
+
_maxUploadRetryTime: number;
|
|
64
|
+
_maxDownloadRetryTime: number;
|
|
65
|
+
_maxOperationRetryTime: number;
|
|
66
|
+
|
|
67
|
+
constructor(
|
|
68
|
+
app: ReactNativeFirebase.FirebaseAppBase,
|
|
69
|
+
config: ModuleConfig,
|
|
70
|
+
bucketUrl?: string | null,
|
|
71
|
+
) {
|
|
72
|
+
super(app, config, bucketUrl ?? undefined);
|
|
73
|
+
if (bucketUrl == null) {
|
|
74
|
+
this._customUrlOrRegion = `gs://${app.options.storageBucket}`;
|
|
75
|
+
} else if (!isString(bucketUrl) || !bucketUrl.startsWith('gs://')) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
"firebase.app().storage(*) bucket url must be a string and begin with 'gs://'",
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const storageEvent = nativeEvents[0];
|
|
82
|
+
|
|
83
|
+
if (!storageEvent) {
|
|
84
|
+
throw new Error('storage_event is not defined in nativeEvents');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.emitter.addListener(
|
|
88
|
+
this.eventNameForApp(storageEvent),
|
|
89
|
+
handleStorageEvent.bind(null, this),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Emulator instance vars needed to send through on iOS, iOS does not persist emulator state between calls
|
|
93
|
+
this.emulatorHost = undefined;
|
|
94
|
+
this.emulatorPort = 0;
|
|
95
|
+
this._maxUploadRetryTime = this.native.maxUploadRetryTime || 0;
|
|
96
|
+
this._maxDownloadRetryTime = this.native.maxDownloadRetryTime || 0;
|
|
97
|
+
this._maxOperationRetryTime = this.native.maxOperationRetryTime || 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setmaxuploadretrytime
|
|
102
|
+
*/
|
|
103
|
+
get maxUploadRetryTime(): number {
|
|
104
|
+
return this._maxUploadRetryTime;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setmaxdownloadretrytime
|
|
109
|
+
*/
|
|
110
|
+
get maxDownloadRetryTime(): number {
|
|
111
|
+
return this._maxDownloadRetryTime;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#maxoperationretrytime
|
|
116
|
+
*/
|
|
117
|
+
get maxOperationRetryTime(): number {
|
|
118
|
+
return this._maxOperationRetryTime;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#ref
|
|
123
|
+
*/
|
|
124
|
+
ref(path: string = '/'): Reference {
|
|
125
|
+
if (!isString(path)) {
|
|
126
|
+
throw new Error("firebase.storage().ref(*) 'path' must be a string value.");
|
|
127
|
+
}
|
|
128
|
+
return new Reference(this, path) as Reference;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#refFromURL
|
|
133
|
+
*/
|
|
134
|
+
refFromURL(url: string): Reference {
|
|
135
|
+
if (!isString(url) || (!url.startsWith('gs://') && !url.startsWith('http'))) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
"firebase.storage().refFromURL(*) 'url' must be a string value and begin with 'gs://' or 'https://'.",
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let path: string;
|
|
142
|
+
let bucket: string;
|
|
143
|
+
|
|
144
|
+
if (url.startsWith('http')) {
|
|
145
|
+
const parts = getHttpUrlParts(url);
|
|
146
|
+
if (!parts) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
"firebase.storage().refFromURL(*) unable to parse 'url', ensure it's a valid storage url'.",
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
({ bucket, path } = parts);
|
|
152
|
+
} else {
|
|
153
|
+
({ bucket, path } = getGsUrlParts(url));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const storageInstance = getOrCreateModularInstance(
|
|
157
|
+
FirebaseStorageModule,
|
|
158
|
+
config,
|
|
159
|
+
this.app,
|
|
160
|
+
bucket,
|
|
161
|
+
) as unknown as StorageInternal;
|
|
162
|
+
return new Reference(storageInstance, path);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setMaxOperationRetryTime
|
|
167
|
+
*/
|
|
168
|
+
setMaxOperationRetryTime(time: number): Promise<void> {
|
|
169
|
+
if (!isNumber(time)) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
"firebase.storage().setMaxOperationRetryTime(*) 'time' must be a number value.",
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this._maxOperationRetryTime = time;
|
|
176
|
+
return this.native.setMaxOperationRetryTime(time);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setMaxUploadRetryTime
|
|
181
|
+
*/
|
|
182
|
+
setMaxUploadRetryTime(time: number): Promise<void> {
|
|
183
|
+
if (!isNumber(time)) {
|
|
184
|
+
throw new Error("firebase.storage().setMaxUploadRetryTime(*) 'time' must be a number value.");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this._maxUploadRetryTime = time;
|
|
188
|
+
return this.native.setMaxUploadRetryTime(time);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @url https://firebase.google.com/docs/reference/js/firebase.storage.Storage#setMaxDownloadRetryTime
|
|
193
|
+
*/
|
|
194
|
+
setMaxDownloadRetryTime(time: number): Promise<void> {
|
|
195
|
+
if (!isNumber(time)) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
"firebase.storage().setMaxDownloadRetryTime(*) 'time' must be a number value.",
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
this._maxDownloadRetryTime = time;
|
|
202
|
+
return this.native.setMaxDownloadRetryTime(time);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
useEmulator(host: string, port: number, _options?: EmulatorMockTokenOptions): void {
|
|
206
|
+
if (!host || !isString(host) || !port || !isNumber(port)) {
|
|
207
|
+
throw new Error('firebase.storage().useEmulator() takes a non-empty host and port');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
let _host = host;
|
|
211
|
+
|
|
212
|
+
const androidBypassEmulatorUrlRemap =
|
|
213
|
+
typeof this.firebaseJson.android_bypass_emulator_url_remap === 'boolean' &&
|
|
214
|
+
this.firebaseJson.android_bypass_emulator_url_remap;
|
|
215
|
+
if (!androidBypassEmulatorUrlRemap && isAndroid && _host) {
|
|
216
|
+
if (_host === 'localhost' || _host === '127.0.0.1') {
|
|
217
|
+
_host = '10.0.2.2';
|
|
218
|
+
// eslint-disable-next-line no-console
|
|
219
|
+
console.log(
|
|
220
|
+
'Mapping storage host to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.',
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
this.emulatorHost = host;
|
|
225
|
+
this.emulatorPort = port;
|
|
226
|
+
this.native.useEmulator(_host, port, this._customUrlOrRegion);
|
|
227
|
+
// @ts-ignore undocumented return, just used to unit test android host remapping
|
|
228
|
+
return [_host, port];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export const SDK_VERSION = version;
|
|
233
|
+
|
|
234
|
+
export function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage {
|
|
235
|
+
return getOrCreateModularInstance(
|
|
236
|
+
FirebaseStorageModule,
|
|
237
|
+
config,
|
|
238
|
+
app,
|
|
239
|
+
bucketUrl,
|
|
240
|
+
) as unknown as FirebaseStorage;
|
|
241
|
+
}
|
|
242
|
+
|
|
19
243
|
export type * from './types/storage';
|
|
244
|
+
export { StringFormat, TaskEvent, TaskState } from './StorageStatics';
|
|
245
|
+
|
|
246
|
+
function isUrl(path?: string): boolean {
|
|
247
|
+
if (typeof path !== 'string') {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return /^[A-Za-z]+:\/\//.test(decodeURIComponent(path));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Modify this Storage instance to communicate with the Firebase Storage emulator.
|
|
256
|
+
* @param storage - Storage instance.
|
|
257
|
+
* @param host - emulator host (e.g. - 'localhost')
|
|
258
|
+
* @param port - emulator port (e.g. - 9199)
|
|
259
|
+
* @param options - `EmulatorMockTokenOptions` instance. Optional. Web only.
|
|
260
|
+
* @returns {void}
|
|
261
|
+
*/
|
|
262
|
+
export function connectStorageEmulator(
|
|
263
|
+
storage: FirebaseStorage,
|
|
264
|
+
host: string,
|
|
265
|
+
port: number,
|
|
266
|
+
options?: EmulatorMockTokenOptions,
|
|
267
|
+
): void {
|
|
268
|
+
return (storage as StorageInternal).useEmulator(host, port, options);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Returns a StorageReference for the given URL or path in the default bucket.
|
|
273
|
+
* @param storage - FirebaseStorage instance.
|
|
274
|
+
* @param url - Optional gs:// or https:// URL, or path. If empty, returns root reference.
|
|
275
|
+
* @returns {StorageReference}
|
|
276
|
+
*/
|
|
277
|
+
export function ref(storage: FirebaseStorage, url?: string): StorageReference;
|
|
278
|
+
/**
|
|
279
|
+
* Returns a StorageReference for the given path, or the same reference if path is omitted.
|
|
280
|
+
* @param storageRef - StorageReference instance.
|
|
281
|
+
* @param path - Optional child path. If omitted, returns the same reference.
|
|
282
|
+
* @returns {StorageReference}
|
|
283
|
+
*/
|
|
284
|
+
export function ref(storageRef: StorageReference, path?: string): StorageReference;
|
|
285
|
+
export function ref(
|
|
286
|
+
storageOrRef: FirebaseStorage | StorageReference,
|
|
287
|
+
path?: string,
|
|
288
|
+
): StorageReference {
|
|
289
|
+
// ref(parentRef, path) → child reference; ref(parentRef) → same reference (firebase-js-sdk overload)
|
|
290
|
+
if (typeof (storageOrRef as StorageReference).fullPath === 'string') {
|
|
291
|
+
if (path === undefined) {
|
|
292
|
+
return storageOrRef as StorageReference;
|
|
293
|
+
}
|
|
294
|
+
return (storageOrRef as StorageReferenceInternal).child(path);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const storage = storageOrRef as FirebaseStorage;
|
|
298
|
+
|
|
299
|
+
if (path != null && isUrl(path)) {
|
|
300
|
+
return (storage as StorageInternal).refFromURL(path);
|
|
301
|
+
}
|
|
302
|
+
return (storage as StorageInternal).ref(path);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Deletes the object at this reference's location.
|
|
307
|
+
* @param storageRef - Storage `Reference` instance.
|
|
308
|
+
* @returns {Promise<void>}
|
|
309
|
+
*/
|
|
310
|
+
export function deleteObject(storageRef: StorageReference): Promise<void> {
|
|
311
|
+
return (storageRef as StorageReferenceInternal).delete();
|
|
312
|
+
}
|
|
20
313
|
|
|
21
|
-
|
|
22
|
-
|
|
314
|
+
/**
|
|
315
|
+
* Downloads the data at the object's location. Returns an error if the object is not found.
|
|
316
|
+
* @param _storageRef - Storage `Reference` instance.
|
|
317
|
+
* @param _maxDownloadSizeBytes - The maximum allowed size in bytes to retrieve. Web only.
|
|
318
|
+
* @returns {Promise<Blob>}
|
|
319
|
+
*/
|
|
320
|
+
export function getBlob(
|
|
321
|
+
_storageRef: StorageReference,
|
|
322
|
+
_maxDownloadSizeBytes?: number,
|
|
323
|
+
): Promise<Blob> {
|
|
324
|
+
throw new Error('`getBlob()` is not implemented');
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Downloads the data at the object's location. Returns an error if the object is not found.
|
|
329
|
+
* @param _storageRef - Storage `Reference` instance.
|
|
330
|
+
* @param _maxDownloadSizeBytes - The maximum allowed size in bytes to retrieve. Web only.
|
|
331
|
+
* @returns {Promise<ArrayBuffer>}
|
|
332
|
+
*/
|
|
333
|
+
export function getBytes(
|
|
334
|
+
_storageRef: StorageReference,
|
|
335
|
+
_maxDownloadSizeBytes?: number,
|
|
336
|
+
): Promise<ArrayBuffer> {
|
|
337
|
+
throw new Error('`getBytes()` is not implemented');
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Deletes the object at this reference's location.
|
|
342
|
+
* @param storageRef - Storage `Reference` instance.
|
|
343
|
+
* @returns {Promise<string>}
|
|
344
|
+
*/
|
|
345
|
+
export function getDownloadURL(storageRef: StorageReference): Promise<string> {
|
|
346
|
+
return (storageRef as StorageReferenceInternal).getDownloadURL();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Fetches metadata for the object at this location, if one exists.
|
|
351
|
+
* @param storageRef - Storage `Reference` instance.
|
|
352
|
+
* @returns {Promise<FullMetadata>}
|
|
353
|
+
*/
|
|
354
|
+
export function getMetadata(storageRef: StorageReference): Promise<FullMetadata> {
|
|
355
|
+
return (storageRef as StorageReferenceInternal).getMetadata();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Downloads the data at the object's location. This API is only available in Nodejs.
|
|
360
|
+
* @param _storageRef - Storage `Reference` instance.
|
|
361
|
+
* @param _maxDownloadSizeBytes - The maximum allowed size in bytes to retrieve. Web only.
|
|
362
|
+
* @returns {NodeJS.ReadableStream;}
|
|
363
|
+
*/
|
|
364
|
+
export function getStream(
|
|
365
|
+
_storageRef: StorageReference,
|
|
366
|
+
_maxDownloadSizeBytes?: number,
|
|
367
|
+
): NodeJS.ReadableStream {
|
|
368
|
+
throw new Error('`getStream()` is not implemented');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* List items (files) and prefixes (folders) under this storage reference
|
|
373
|
+
* @param storageRef - Storage `Reference` instance.
|
|
374
|
+
* @param options - Storage `ListOptions` instance. The options list() accepts.
|
|
375
|
+
* @returns {Promise<ListResult>}
|
|
376
|
+
*/
|
|
377
|
+
export async function list(
|
|
378
|
+
storageRef: StorageReference,
|
|
379
|
+
options?: ListOptions,
|
|
380
|
+
): Promise<ListResult> {
|
|
381
|
+
const result = await (storageRef as StorageReferenceInternal).list(options);
|
|
382
|
+
|
|
383
|
+
if (result.nextPageToken === null) {
|
|
384
|
+
delete result.nextPageToken;
|
|
385
|
+
}
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* List all items (files) and prefixes (folders) under this storage reference.
|
|
391
|
+
* @param storageRef - Storage `Reference` instance.
|
|
392
|
+
* @returns {Promise<ListResult>}
|
|
393
|
+
*/
|
|
394
|
+
export async function listAll(storageRef: StorageReference): Promise<ListResult> {
|
|
395
|
+
const result = await (storageRef as StorageReferenceInternal).listAll();
|
|
396
|
+
|
|
397
|
+
if (result.nextPageToken === null) {
|
|
398
|
+
delete result.nextPageToken;
|
|
399
|
+
}
|
|
400
|
+
return result;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Updates the metadata for this object.
|
|
405
|
+
* @param storageRef - Storage `Reference` instance.
|
|
406
|
+
* @param metadata - A Storage `SettableMetadata` instance to update.
|
|
407
|
+
* @returns {Promise<FullMetadata>}
|
|
408
|
+
*/
|
|
409
|
+
export function updateMetadata(
|
|
410
|
+
storageRef: StorageReference,
|
|
411
|
+
metadata: SettableMetadata,
|
|
412
|
+
): Promise<FullMetadata> {
|
|
413
|
+
return (storageRef as StorageReferenceInternal).updateMetadata(metadata);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Uploads data to this object's location. The upload is not resumable.
|
|
418
|
+
* @param _storageRef - Storage `Reference` instance.
|
|
419
|
+
* @param _data - The data (Blob | Uint8Array | ArrayBuffer) to upload to the storage bucket at the reference location.
|
|
420
|
+
* @param _metadata - A Storage `UploadMetadata` instance to update. Optional.
|
|
421
|
+
* @returns {Promise<UploadResult>}
|
|
422
|
+
*/
|
|
423
|
+
export async function uploadBytes(
|
|
424
|
+
_storageRef: StorageReference,
|
|
425
|
+
_data: Blob | Uint8Array | ArrayBuffer,
|
|
426
|
+
_metadata?: UploadMetadata,
|
|
427
|
+
): Promise<UploadResult> {
|
|
428
|
+
throw new Error('`uploadBytes()` is not implemented');
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Uploads data to this object's location. The upload is not resumable.
|
|
433
|
+
* @param storageRef - Storage `Reference` instance.
|
|
434
|
+
* @param data - The data (Blob | Uint8Array | ArrayBuffer) to upload to the storage bucket at the reference location.
|
|
435
|
+
* @param metadata - A Storage `UploadMetadata` instance to update. Optional.
|
|
436
|
+
* @returns {UploadTask}
|
|
437
|
+
*/
|
|
438
|
+
export function uploadBytesResumable(
|
|
439
|
+
storageRef: StorageReference,
|
|
440
|
+
data: Blob | Uint8Array | ArrayBuffer,
|
|
441
|
+
metadata?: UploadMetadata,
|
|
442
|
+
): UploadTask {
|
|
443
|
+
return (storageRef as StorageReferenceInternal).put(data, metadata);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Uploads data to this object's location. The upload is not resumable.
|
|
448
|
+
* @param storageRef - Storage `Reference` instance.
|
|
449
|
+
* @param data - The string to upload.
|
|
450
|
+
* @param format - The format of the string to upload ('raw' | 'base64' | 'base64url' | 'data_url'). Optional.
|
|
451
|
+
* @param metadata - A Storage `UploadMetadata` instance to update. Optional.
|
|
452
|
+
* @returns {Task}
|
|
453
|
+
*/
|
|
454
|
+
export function uploadString(
|
|
455
|
+
storageRef: StorageReference,
|
|
456
|
+
data: string,
|
|
457
|
+
format?: 'raw' | 'base64' | 'base64url' | 'data_url',
|
|
458
|
+
metadata?: UploadMetadata,
|
|
459
|
+
): Task {
|
|
460
|
+
return (storageRef as StorageReferenceInternal).putString(data, format, metadata);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Methods not on the Firebase JS SDK below
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Sets the maximum time in milliseconds to retry non-upload/download operations.
|
|
467
|
+
*
|
|
468
|
+
* @remarks React Native Firebase-specific modular helper. The firebase-js-sdk exposes this as a
|
|
469
|
+
* writable property on the `FirebaseStorage` instance. **Android and iOS only.**
|
|
470
|
+
*/
|
|
471
|
+
export function setMaxOperationRetryTime(storage: FirebaseStorage, time: number): Promise<void> {
|
|
472
|
+
return (storage as StorageInternal).setMaxOperationRetryTime(time);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Sets the maximum time in milliseconds to retry an upload if a failure occurs.
|
|
477
|
+
*
|
|
478
|
+
* @remarks React Native Firebase-specific modular helper. The firebase-js-sdk exposes this as a
|
|
479
|
+
* writable property on the `FirebaseStorage` instance. **Android and iOS only.**
|
|
480
|
+
*/
|
|
481
|
+
export function setMaxUploadRetryTime(storage: FirebaseStorage, time: number): Promise<void> {
|
|
482
|
+
return (storage as StorageInternal).setMaxUploadRetryTime(time);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Uploads a file from a local device path to Cloud Storage.
|
|
487
|
+
*
|
|
488
|
+
* @remarks React Native Firebase-specific API with **no firebase-js-sdk equivalent**. Use
|
|
489
|
+
* `FilePath` from `@react-native-firebase/app` for portable device paths. **Native only**
|
|
490
|
+
* — throws on Web interop.
|
|
491
|
+
*/
|
|
492
|
+
export function putFile(
|
|
493
|
+
storageRef: StorageReference,
|
|
494
|
+
filePath: string,
|
|
495
|
+
metadata?: UploadMetadata,
|
|
496
|
+
): Task {
|
|
497
|
+
return (storageRef as StorageReferenceInternal).putFile(filePath, metadata);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Downloads a Cloud Storage object to a local device file path.
|
|
502
|
+
*
|
|
503
|
+
* @remarks React Native Firebase-specific API with **no firebase-js-sdk equivalent**. Use
|
|
504
|
+
* `FilePath` from `@react-native-firebase/app` for portable device paths. **Native only**
|
|
505
|
+
* — throws on Web interop.
|
|
506
|
+
*/
|
|
507
|
+
export function writeToFile(storageRef: StorageReference, filePath: string): Task {
|
|
508
|
+
return (storageRef as StorageReferenceInternal).writeToFile(filePath);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Sets the maximum time in milliseconds to retry a download if a failure occurs.
|
|
513
|
+
*
|
|
514
|
+
* @remarks React Native Firebase-specific modular helper with no direct firebase-js-sdk equivalent.
|
|
515
|
+
* **Android and iOS only.**
|
|
516
|
+
*/
|
|
517
|
+
export function setMaxDownloadRetryTime(storage: FirebaseStorage, time: number): Promise<void> {
|
|
518
|
+
return (storage as StorageInternal).setMaxDownloadRetryTime(time);
|
|
519
|
+
}
|
|
23
520
|
|
|
24
|
-
|
|
25
|
-
export type { FirebaseStorageTypes } from './types/namespaced';
|
|
26
|
-
export * from './namespaced';
|
|
27
|
-
export { default } from './namespaced';
|
|
521
|
+
setReactNativeModule(nativeModuleName, fallBackModule);
|
package/lib/types/internal.ts
CHANGED
|
@@ -35,7 +35,7 @@ import type EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitte
|
|
|
35
35
|
* Used internally by StorageReference and other internal classes.
|
|
36
36
|
*/
|
|
37
37
|
export type StorageInternal = FirebaseStorage & {
|
|
38
|
-
native:
|
|
38
|
+
native: NativeRNFBTurboStorage;
|
|
39
39
|
_customUrlOrRegion: string | null;
|
|
40
40
|
emitter: EventEmitter;
|
|
41
41
|
eventNameForApp: (...args: Array<string | number>) => string;
|
|
@@ -127,7 +127,7 @@ export type ListResultInternal = {
|
|
|
127
127
|
* when `hasMultiAppSupport` is enabled. This interface represents the *wrapped* module shape
|
|
128
128
|
* that is exposed as `this.native` within FirebaseModule subclasses.
|
|
129
129
|
*/
|
|
130
|
-
export interface
|
|
130
|
+
export interface NativeRNFBTurboStorage {
|
|
131
131
|
/**
|
|
132
132
|
* Native constants exposed on the module.
|
|
133
133
|
* These are read during module construction to seed the JS-side values.
|
|
@@ -140,7 +140,7 @@ export interface RNFBStorageModule {
|
|
|
140
140
|
setMaxUploadRetryTime(time: number): Promise<void>;
|
|
141
141
|
setMaxDownloadRetryTime(time: number): Promise<void>;
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
deleteObject(url: string): Promise<void>;
|
|
144
144
|
getDownloadURL(url: string): Promise<string>;
|
|
145
145
|
getMetadata(url: string): Promise<FullMetadata>;
|
|
146
146
|
updateMetadata(url: string, metadata: SettableMetadata): Promise<FullMetadata>;
|
|
@@ -172,7 +172,7 @@ export interface RNFBStorageModule {
|
|
|
172
172
|
* - 1: resume
|
|
173
173
|
* - 2: cancel
|
|
174
174
|
*/
|
|
175
|
-
setTaskStatus(taskId: number, status: number):
|
|
175
|
+
setTaskStatus(taskId: number, status: number): boolean;
|
|
176
176
|
|
|
177
177
|
/**
|
|
178
178
|
* Configure storage emulator.
|
|
@@ -184,6 +184,6 @@ export interface RNFBStorageModule {
|
|
|
184
184
|
|
|
185
185
|
declare module '@react-native-firebase/app/dist/module/internal/NativeModules' {
|
|
186
186
|
interface ReactNativeFirebaseNativeModules {
|
|
187
|
-
|
|
187
|
+
NativeRNFBTurboStorage: NativeRNFBTurboStorage;
|
|
188
188
|
}
|
|
189
189
|
}
|
package/lib/types/storage.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
import type { FirebaseApp, ReactNativeFirebase } from '@react-native-firebase/app';
|
|
18
|
+
import type { FirebaseError } from '@firebase/app';
|
|
18
19
|
import type {
|
|
19
20
|
CompleteFn,
|
|
20
21
|
NextFn,
|
|
@@ -22,6 +23,14 @@ import type {
|
|
|
22
23
|
} from '@react-native-firebase/app/dist/module/types/common';
|
|
23
24
|
export type { CompleteFn, NextFn, Unsubscribe };
|
|
24
25
|
export type NativeFirebaseError = ReactNativeFirebase.NativeFirebaseError;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Storage failure error type for public observer callbacks.
|
|
29
|
+
* Runtime values are {@link NativeFirebaseError} instances structurally compatible with `FirebaseError`.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export type StorageError = FirebaseError;
|
|
33
|
+
|
|
25
34
|
/**
|
|
26
35
|
* Storage module instance
|
|
27
36
|
*/
|
|
@@ -260,15 +269,13 @@ export const TaskState = {
|
|
|
260
269
|
*/
|
|
261
270
|
export interface StorageObserver<T> {
|
|
262
271
|
next?: NextFn<T> | null;
|
|
263
|
-
error?: ((error:
|
|
272
|
+
error?: ((error: StorageError) => unknown) | null;
|
|
264
273
|
complete?: CompleteFn | null;
|
|
265
274
|
}
|
|
266
275
|
|
|
267
276
|
/**
|
|
268
277
|
* Represents the process of uploading an object. Allows you to monitor and manage the upload.
|
|
269
278
|
*
|
|
270
|
-
* Note: React Native Firebase returns Promises for pause/resume/cancel to communicate with native iOS/Android.
|
|
271
|
-
*
|
|
272
279
|
* @public
|
|
273
280
|
*/
|
|
274
281
|
export interface UploadTask {
|
|
@@ -276,12 +283,12 @@ export interface UploadTask {
|
|
|
276
283
|
* Cancels a running task. Has no effect on a complete or failed task.
|
|
277
284
|
* @returns True if the cancel had an effect.
|
|
278
285
|
*/
|
|
279
|
-
cancel():
|
|
286
|
+
cancel(): boolean;
|
|
280
287
|
|
|
281
288
|
/**
|
|
282
289
|
* Equivalent to calling `then(null, onRejected)`.
|
|
283
290
|
*/
|
|
284
|
-
catch(onRejected: (error:
|
|
291
|
+
catch(onRejected: (error: StorageError) => unknown): Promise<unknown>;
|
|
285
292
|
|
|
286
293
|
/**
|
|
287
294
|
* Listens for events on this task.
|
|
@@ -295,7 +302,7 @@ export interface UploadTask {
|
|
|
295
302
|
| StorageObserver<UploadTaskSnapshot>
|
|
296
303
|
| null
|
|
297
304
|
| ((snapshot: UploadTaskSnapshot) => unknown),
|
|
298
|
-
error?: ((error:
|
|
305
|
+
error?: ((error: StorageError) => unknown) | null,
|
|
299
306
|
complete?: CompleteFn | null,
|
|
300
307
|
): Unsubscribe | Subscribe<UploadTaskSnapshot>;
|
|
301
308
|
|
|
@@ -303,13 +310,13 @@ export interface UploadTask {
|
|
|
303
310
|
* Pauses a currently running task. Has no effect on a paused or failed task.
|
|
304
311
|
* @returns True if the operation took effect, false if ignored.
|
|
305
312
|
*/
|
|
306
|
-
pause():
|
|
313
|
+
pause(): boolean;
|
|
307
314
|
|
|
308
315
|
/**
|
|
309
316
|
* Resumes a paused task. Has no effect on a currently running or failed task.
|
|
310
317
|
* @returns True if the operation took effect, false if ignored.
|
|
311
318
|
*/
|
|
312
|
-
resume():
|
|
319
|
+
resume(): boolean;
|
|
313
320
|
|
|
314
321
|
/**
|
|
315
322
|
* A snapshot of the current task state.
|
|
@@ -321,7 +328,7 @@ export interface UploadTask {
|
|
|
321
328
|
*/
|
|
322
329
|
then(
|
|
323
330
|
onFulfilled?: ((snapshot: UploadTaskSnapshot) => unknown) | null,
|
|
324
|
-
onRejected?: ((error:
|
|
331
|
+
onRejected?: ((error: StorageError) => unknown) | null,
|
|
325
332
|
): Promise<unknown>;
|
|
326
333
|
}
|
|
327
334
|
|
|
@@ -380,7 +387,7 @@ export interface UploadResult {
|
|
|
380
387
|
|
|
381
388
|
export type Subscribe<T> = (
|
|
382
389
|
nextOrObserver?: StorageObserver<T> | null | NextFn<T>,
|
|
383
|
-
error?: ((error:
|
|
390
|
+
error?: ((error: StorageError) => unknown) | null,
|
|
384
391
|
complete?: CompleteFn | null,
|
|
385
392
|
) => Unsubscribe;
|
|
386
393
|
|
package/lib/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '
|
|
2
|
+
export const version = '26.0.0';
|