@react-native-firebase/storage 20.2.1 → 20.4.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [20.4.0](https://github.com/invertase/react-native-firebase/compare/v20.3.0...v20.4.0) (2024-08-13)
7
+
8
+ ### Features
9
+
10
+ - **firestore:** support for second database ([#7949](https://github.com/invertase/react-native-firebase/issues/7949)) ([eec08a0](https://github.com/invertase/react-native-firebase/commit/eec08a06f41dd96d13778fbed2afcaaac238fca4))
11
+
12
+ ## [20.3.0](https://github.com/invertase/react-native-firebase/compare/v20.2.1...v20.3.0) (2024-07-19)
13
+
14
+ **Note:** Version bump only for package @react-native-firebase/storage
15
+
6
16
  ## [20.2.1](https://github.com/invertase/react-native-firebase/compare/v20.2.0...v20.2.1) (2024-07-17)
7
17
 
8
18
  ### Bug Fixes
@@ -1,6 +1,31 @@
1
1
  import { describe, expect, it } from '@jest/globals';
2
2
 
3
- import storage, { firebase } from '../lib';
3
+ import storage, {
4
+ firebase,
5
+ getStorage,
6
+ connectStorageEmulator,
7
+ ref,
8
+ deleteObject,
9
+ getBlob,
10
+ getBytes,
11
+ getDownloadURL,
12
+ getMetadata,
13
+ getStream,
14
+ list,
15
+ listAll,
16
+ updateMetadata,
17
+ uploadBytes,
18
+ uploadBytesResumable,
19
+ uploadString,
20
+ refFromURL,
21
+ setMaxOperationRetryTime,
22
+ setMaxUploadRetryTime,
23
+ putFile,
24
+ writeToFile,
25
+ toString,
26
+ child,
27
+ setMaxDownloadRetryTime,
28
+ } from '../lib';
4
29
 
5
30
  describe('Storage', function () {
6
31
  describe('namespace', function () {
@@ -45,4 +70,98 @@ describe('Storage', function () {
45
70
  expect(bar).toEqual(['10.0.2.2', 9000]);
46
71
  });
47
72
  });
73
+
74
+ describe('modular', function () {
75
+ it('`getStorage` function is properly exposed to end user', function () {
76
+ expect(getStorage).toBeDefined();
77
+ });
78
+
79
+ it('`connectStorageEmulator` function is properly exposed to end user', function () {
80
+ expect(connectStorageEmulator).toBeDefined();
81
+ });
82
+
83
+ it('`ref` function is properly exposed to end user', function () {
84
+ expect(ref).toBeDefined();
85
+ });
86
+
87
+ it('`deleteObject` function is properly exposed to end user', function () {
88
+ expect(deleteObject).toBeDefined();
89
+ });
90
+
91
+ it('`getBlob` function is properly exposed to end user', function () {
92
+ expect(getBlob).toBeDefined();
93
+ });
94
+
95
+ it('`getBytes` function is properly exposed to end user', function () {
96
+ expect(getBytes).toBeDefined();
97
+ });
98
+
99
+ it('`getDownloadURL` function is properly exposed to end user', function () {
100
+ expect(getDownloadURL).toBeDefined();
101
+ });
102
+
103
+ it('`getMetadata` function is properly exposed to end user', function () {
104
+ expect(getMetadata).toBeDefined();
105
+ });
106
+
107
+ it('`getStream` function is properly exposed to end user', function () {
108
+ expect(getStream).toBeDefined();
109
+ });
110
+
111
+ it('`list` function is properly exposed to end user', function () {
112
+ expect(list).toBeDefined();
113
+ });
114
+
115
+ it('`listAll` function is properly exposed to end user', function () {
116
+ expect(listAll).toBeDefined();
117
+ });
118
+
119
+ it('`updateMetadata` function is properly exposed to end user', function () {
120
+ expect(updateMetadata).toBeDefined();
121
+ });
122
+
123
+ it('`uploadBytes` function is properly exposed to end user', function () {
124
+ expect(uploadBytes).toBeDefined();
125
+ });
126
+
127
+ it('`uploadBytesResumable` function is properly exposed to end user', function () {
128
+ expect(uploadBytesResumable).toBeDefined();
129
+ });
130
+
131
+ it('`uploadString` function is properly exposed to end user', function () {
132
+ expect(uploadString).toBeDefined();
133
+ });
134
+
135
+ it('`refFromURL` function is properly exposed to end user', function () {
136
+ expect(refFromURL).toBeDefined();
137
+ });
138
+
139
+ it('`setMaxOperationRetryTime` function is properly exposed to end user', function () {
140
+ expect(setMaxOperationRetryTime).toBeDefined();
141
+ });
142
+
143
+ it('`setMaxUploadRetryTime` function is properly exposed to end user', function () {
144
+ expect(setMaxUploadRetryTime).toBeDefined();
145
+ });
146
+
147
+ it('`putFile` function is properly exposed to end user', function () {
148
+ expect(putFile).toBeDefined();
149
+ });
150
+
151
+ it('`writeToFile` function is properly exposed to end user', function () {
152
+ expect(writeToFile).toBeDefined();
153
+ });
154
+
155
+ it('`toString` function is properly exposed to end user', function () {
156
+ expect(toString).toBeDefined();
157
+ });
158
+
159
+ it('`child` function is properly exposed to end user', function () {
160
+ expect(child).toBeDefined();
161
+ });
162
+
163
+ it('`setMaxDownloadRetryTime` function is properly exposed to end user', function () {
164
+ expect(setMaxDownloadRetryTime).toBeDefined();
165
+ });
166
+ });
48
167
  });
@@ -281,7 +281,8 @@ public class ReactNativeFirebaseStorageModule extends ReactNativeFirebaseModule
281
281
  * @link https://firebase.google.com/docs/reference/js/firebase.storage.Storage#useEmulator
282
282
  */
283
283
  @ReactMethod
284
- public void useEmulator(String appName, String host, int port, String bucketUrl, Promise promise) {
284
+ public void useEmulator(
285
+ String appName, String host, int port, String bucketUrl, Promise promise) {
285
286
  FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
286
287
 
287
288
  FirebaseStorage firebaseStorage = FirebaseStorage.getInstance(firebaseApp, bucketUrl);
package/lib/index.d.ts CHANGED
@@ -1172,3 +1172,5 @@ declare module '@react-native-firebase/app' {
1172
1172
  }
1173
1173
  }
1174
1174
  }
1175
+
1176
+ export * from './modular';
package/lib/index.js CHANGED
@@ -28,31 +28,6 @@ import { getGsUrlParts, getHttpUrlParts, handleStorageEvent } from './utils';
28
28
  import version from './version';
29
29
  import fallBackModule from './web/RNFBStorageModule';
30
30
 
31
- export {
32
- getStorage,
33
- connectStorageEmulator,
34
- ref,
35
- deleteObject,
36
- getBlob,
37
- getBytes,
38
- getDownloadURL,
39
- getMetadata,
40
- getStream,
41
- list,
42
- listAll,
43
- updateMetadata,
44
- putFile,
45
- writeToFile,
46
- toString,
47
- child,
48
- setMaxDownloadRetryTime,
49
- setMaxOperationRetryTime,
50
- setMaxUploadRetryTime,
51
- refFromURL,
52
- uploadString,
53
- uploadBytesResumable,
54
- } from '../modular/index';
55
-
56
31
  const namespace = 'storage';
57
32
  const nativeEvents = ['storage_event'];
58
33
  const nativeModuleName = 'RNFBStorageModule';
@@ -233,4 +208,6 @@ export default createModuleNamespace({
233
208
  // firebase.storage().X(...);
234
209
  export const firebase = getFirebaseRoot();
235
210
 
211
+ export * from './modular';
212
+
236
213
  setReactNativeModule(nativeModuleName, fallBackModule);
@@ -0,0 +1,261 @@
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 { FirebaseApp } from '@firebase/app-types';
19
+ import { FirebaseStorageTypes } from '../index';
20
+
21
+ import Storage = FirebaseStorageTypes.Module;
22
+ import Reference = FirebaseStorageTypes.Reference;
23
+ import FullMetadata = FirebaseStorageTypes.FullMetadata;
24
+ import ListResult = FirebaseStorageTypes.ListResult;
25
+ import TaskResult = FirebaseStorageTypes.TaskResult;
26
+ import Task = FirebaseStorageTypes.Task;
27
+ import ListOptions = FirebaseStorageTypes.ListOptions;
28
+ import SettableMetadata = FirebaseStorageTypes.SettableMetadata;
29
+ import EmulatorMockTokenOptions = FirebaseStorageTypes.EmulatorMockTokenOptions;
30
+
31
+ /**
32
+ * Returns the existing default {@link Storage} instance that is associated with the
33
+ * default {@link FirebaseApp}. The default storage bucket is used. If no instance exists, initializes a new
34
+ * instance with default settings.
35
+ *
36
+ * @returns The {@link Storage} instance of the provided app.
37
+ */
38
+ export declare function getStorage(): Storage;
39
+
40
+ /**
41
+ * Returns the existing default {@link Storage} instance that is associated with the
42
+ * provided {@link FirebaseApp}. The default storage bucket is used. If no instance exists, initializes a new
43
+ * instance with default settings.
44
+ *
45
+ * @param app - The {@link FirebaseApp} instance that the returned {@link Storage}
46
+ * instance is associated with.
47
+ * @returns The {@link Firestore} instance of the provided app.
48
+ */
49
+ export declare function getStorage(app?: FirebaseApp): Storage;
50
+
51
+ /**
52
+ * Returns the existing default {@link Storage} instance that is associated with the
53
+ * provided {@link FirebaseApp}. If no instance exists, initializes a new
54
+ * instance with default settings.
55
+ *
56
+ * @param app - The {@link FirebaseApp} instance that the returned {@link Storage}
57
+ * instance is associated with. If `null` the default app is used.
58
+ * @param bucketUrl - The gs:// url to the Firebase Storage Bucket. If `null` the default bucket is used.
59
+ * @returns The {@link Firestore} instance of the provided app.
60
+ */
61
+ export declare function getStorage(app?: FirebaseApp, bucketUrl?: string): Storage;
62
+
63
+ export function getStorage(app?: FirebaseApp, bucketUrl?: string): Storage;
64
+
65
+ /**
66
+ * Connects a {@link Storage} instance to the Firebase Storage emulator.
67
+ * @param storage - A reference to the `Storage` instance.
68
+ * @param host - Emulator host, e.g., 'localhost'.
69
+ * @param port - Emulator port, e.g., 9199.
70
+ * @param options - Optional. {@link EmulatorMockTokenOptions} instance.
71
+ */
72
+ export function connectStorageEmulator(
73
+ storage: Storage,
74
+ host: string,
75
+ port: number,
76
+ options?: EmulatorMockTokenOptions,
77
+ ): void;
78
+
79
+ /**
80
+ * Creates a {@link Reference} from a given path or URL.
81
+ * @param storage - The {@link Storage} instance.
82
+ * @param path - Optional. A string pointing to a location within the storage bucket.
83
+ * @returns A new {@link Reference}.
84
+ */
85
+ export function ref(storage: Storage, path?: string): Reference;
86
+
87
+ /**
88
+ * Deletes the object at the given reference's location.
89
+ * @param storageRef - The {@link Reference} to the object to delete.
90
+ * @returns A promise that resolves when the delete is complete.
91
+ */
92
+ export function deleteObject(storageRef: Reference): Promise<void>;
93
+
94
+ /**
95
+ * Retrieves the blob at the given reference's location. Throws an error if the object is not found.
96
+ * @param storageRef - The {@link Reference} to the object.
97
+ * @returns A promise resolving to the Blob.
98
+ */
99
+ export function getBlob(storageRef: Reference): Promise<Blob>;
100
+
101
+ /**
102
+ * Retrieves bytes (up to the specified max size) from an object at the given reference's location.
103
+ * Throws an error if the object is not found or if the size exceeds the maximum allowed.
104
+ * @param storageRef - The {@link Reference} to the object.
105
+ * @param maxDownloadSizeBytes - Maximum size in bytes to retrieve.
106
+ * @returns A promise resolving to an ArrayBuffer.
107
+ */
108
+ export function getBytes(storageRef: Reference, maxDownloadSizeBytes: number): Promise<ArrayBuffer>;
109
+
110
+ /**
111
+ * Retrieves a long-lived download URL for the object at the given reference's location.
112
+ * @param storageRef - The {@link Reference} to the object.
113
+ * @returns A promise resolving to the URL string.
114
+ */
115
+ export function getDownloadURL(storageRef: Reference): Promise<string>;
116
+
117
+ /**
118
+ * Retrieves metadata for the object at the given reference's location.
119
+ * @param storageRef - The {@link Reference} to the object.
120
+ * @returns A promise resolving to the object's {@link FullMetadata}.
121
+ */
122
+ export function getMetadata(storageRef: Reference): Promise<FullMetadata>;
123
+
124
+ /**
125
+ * Retrieves a readable stream for the object at the given reference's location. This API is only available in Node.js.
126
+ * @param storageRef - The {@link Reference} to the object.
127
+ * @param maxDownloadSizeBytes - Maximum size in bytes to retrieve.
128
+ * @returns A NodeJS ReadableStream.
129
+ */
130
+ export function getStream(
131
+ storageRef: Reference,
132
+ maxDownloadSizeBytes: number,
133
+ ): NodeJS.ReadableStream;
134
+
135
+ /**
136
+ * Lists items and prefixes under the given reference.
137
+ * @param storageRef - The {@link Reference} under which to list items.
138
+ * @param options - Optional. Configuration for listing.
139
+ * @returns A promise resolving to a {@link ListResult}.
140
+ */
141
+ export function list(storageRef: Reference, options?: ListOptions): Promise<ListResult>;
142
+
143
+ /**
144
+ * Lists all items and prefixes under the given reference.
145
+ * @param storageRef - The {@link Reference} under which to list items.
146
+ * @returns A promise resolving to a {@link ListResult}.
147
+ */
148
+ export function listAll(storageRef: Reference): Promise<ListResult>;
149
+
150
+ /**
151
+ * Updates metadata for the object at the given reference.
152
+ * @param storageRef - The {@link Reference} to the object.
153
+ * @param metadata - The metadata to update.
154
+ * @returns A promise resolving to the updated {@link FullMetadata}.
155
+ */
156
+ export function updateMetadata(
157
+ storageRef: Reference,
158
+ metadata: SettableMetadata,
159
+ ): Promise<FullMetadata>;
160
+
161
+ /**
162
+ * Uploads data to the object's location at the given reference. The upload is not resumable.
163
+ * @param storageRef - The {@link Reference} where the data should be uploaded.
164
+ * @param data - The data to upload.
165
+ * @param metadata - Optional. Metadata to associate with the uploaded object.
166
+ * @returns A promise resolving to a {@link TaskResult}.
167
+ */
168
+ export function uploadBytes(
169
+ storageRef: Reference,
170
+ data: Blob | Uint8Array | ArrayBuffer,
171
+ metadata?: SettableMetadata,
172
+ ): Promise<TaskResult>;
173
+
174
+ /**
175
+ * Initiates a resumable upload session for the data to the object's location at the given reference.
176
+ * @param storageRef - The {@link Reference} where the data should be uploaded.
177
+ * @param data - The data to upload.
178
+ * @param metadata - Optional. Metadata to associate with the uploaded object.
179
+ * @returns A {@link Task} associated with the upload process.
180
+ */
181
+ export function uploadBytesResumable(
182
+ storageRef: Reference,
183
+ data: Blob | Uint8Array | ArrayBuffer,
184
+ metadata?: SettableMetadata,
185
+ ): Task;
186
+
187
+ /**
188
+ * Uploads a string to the object's location at the given reference. The string format must be specified.
189
+ * @param storageRef - The {@link Reference} where the string should be uploaded.
190
+ * @param data - The string data to upload.
191
+ * @param format - Optional. The format of the string ('raw', 'base64', 'base64url', 'data_url').
192
+ * @param metadata - Optional. Metadata to associate with the uploaded object.
193
+ * @returns A {@link Task} associated with the upload process.
194
+ */
195
+ export function uploadString(
196
+ storageRef: Reference,
197
+ data: string,
198
+ format?: 'raw' | 'base64' | 'base64url' | 'data_url',
199
+ metadata?: SettableMetadata,
200
+ ): Task;
201
+
202
+ /**
203
+ * Creates a {@link Reference} from a storage bucket URL.
204
+ * @param storage - The {@link Storage} instance.
205
+ * @param url - A URL pointing to a file or location in a storage bucket.
206
+ * @returns A {@link Reference} pointing to the specified URL.
207
+ */
208
+ export function refFromURL(storage: Storage, url: string): Reference;
209
+
210
+ /**
211
+ * Sets the maximum time in milliseconds to retry operations other than upload and download if a failure occurs.
212
+ * @param storage - The {@link Storage} instance.
213
+ * @param time - The new maximum operation retry time in milliseconds.
214
+ */
215
+ export function setMaxOperationRetryTime(storage: Storage, time: number): Promise<void>;
216
+
217
+ /**
218
+ * Sets the maximum time in milliseconds to retry upload operations if a failure occurs.
219
+ * @param storage - The {@link Storage} instance.
220
+ * @param time - The new maximum upload retry time in milliseconds.
221
+ */
222
+ export function setMaxUploadRetryTime(storage: Storage, time: number): Promise<void>;
223
+
224
+ /**
225
+ * Puts a file from a local disk onto the storage bucket at the given reference.
226
+ * @param storageRef - The {@link Reference} where the file should be uploaded.
227
+ * @param filePath - The local file path of the file to upload.
228
+ * @param metadata - Optional. Metadata to associate with the uploaded file.
229
+ * @returns A {@link Task} associated with the upload process.
230
+ */
231
+ export function putFile(storageRef: Reference, filePath: string, metadata?: SettableMetadata): Task;
232
+
233
+ /**
234
+ * Downloads a file to the specified local file path on the device.
235
+ * @param storageRef - The {@link Reference} from which the file should be downloaded.
236
+ * @param filePath - The local file path where the file should be written.
237
+ * @returns A {@link Task} associated with the download process.
238
+ */
239
+ export function writeToFile(storageRef: Reference, filePath: string): Task;
240
+
241
+ /**
242
+ * Returns a gs:// URL for the object at the given reference.
243
+ * @param storageRef - The {@link Reference} to the object.
244
+ * @returns The URL as a string.
245
+ */
246
+ export function toString(storageRef: Reference): string;
247
+
248
+ /**
249
+ * Returns a reference to a relative path from the given reference.
250
+ * @param storageRef - The {@link Reference} as the base.
251
+ * @param path - The relative path from the base reference.
252
+ * @returns A new {@link Reference}.
253
+ */
254
+ export function child(storageRef: Reference, path: string): Reference;
255
+
256
+ /**
257
+ * Sets the maximum time in milliseconds to retry download operations if a failure occurs.
258
+ * @param storage - The {@link Storage} instance.
259
+ * @param time - The new maximum download retry time in milliseconds.
260
+ */
261
+ export function setMaxDownloadRetryTime(storage: Storage, time: number): Promise<void>;
@@ -14,6 +14,19 @@
14
14
  * limitations under the License.
15
15
  *
16
16
  */
17
+ /**
18
+ * @typedef {import('..').FirebaseStorageTypes} FirebaseStorageTypes
19
+ * @typedef {import('..').FirebaseStorageTypes.Module} Storage
20
+ * @typedef {import('..').FirebaseStorageTypes.Reference} Reference
21
+ * @typedef {import('..').FirebaseStorageTypes.FullMetadata} FullMetadata
22
+ * @typedef {import('..').FirebaseStorageTypes.ListResult} ListResult
23
+ * @typedef {import('..').FirebaseStorageTypes.TaskResult} TaskResult
24
+ * @typedef {import('..').FirebaseStorageTypes.Task} Task
25
+ * @typedef {import('..').FirebaseStorageTypes.ListOptions} ListOptions
26
+ * @typedef {import('..').FirebaseStorageTypes.SettableMetadata} SettableMetadata
27
+ * @typedef {import('..').FirebaseStorageTypes.EmulatorMockTokenOptions} EmulatorMockTokenOptions
28
+ * @typedef {import('@firebase/app').FirebaseApp} FirebaseApp
29
+ */
17
30
 
18
31
  import { firebase } from '..';
19
32
 
@@ -56,7 +69,7 @@ export function connectStorageEmulator(storage, host, port, options) {
56
69
  * @param storage - Storage instance.
57
70
  * @param path An optional string pointing to a location on the storage bucket. If no path
58
71
  * is provided, the returned reference will be the bucket root path. Optional.
59
- * @returns {Storage.Reference}
72
+ * @returns {Reference}
60
73
  */
61
74
  export function ref(storage, path) {
62
75
  return storage.ref(path);
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '20.2.1';
2
+ module.exports = '20.4.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/storage",
3
- "version": "20.2.1",
3
+ "version": "20.4.0",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "React Native Firebase - React Native Firebase provides native integration with Cloud Storage, providing support to upload and download files directly from your device and from your Firebase Cloud Storage bucket.",
6
6
  "main": "lib/index.js",
@@ -29,10 +29,10 @@
29
29
  "download"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@react-native-firebase/app": "20.2.1"
32
+ "@react-native-firebase/app": "20.4.0"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "2c787c2dbefbefcc637018e1e5d74a73b39600ab"
37
+ "gitHead": "3ac3e9623674a8db52c111b4aa0a85a883260116"
38
38
  }