Skip to content

Commit 8a32896

Browse files
MichaelVerdonmikehardy
authored andcommitted
chore(storage): deprecation warnings for v8 API ahead of future major release
1 parent 497c6d1 commit 8a32896

File tree

7 files changed

+420
-125
lines changed

7 files changed

+420
-125
lines changed

packages/app/lib/common/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,35 @@ const mapOfDeprecationReplacements = {
269269
nanoseconds: NO_REPLACEMENT,
270270
},
271271
},
272+
storage: {
273+
default: {
274+
useEmulator: 'connectStorageEmulator()',
275+
ref: 'ref()',
276+
refFromURL: 'refFromURL()',
277+
setMaxOperationRetryTime: 'setMaxOperationRetryTime()',
278+
setMaxUploadRetryTime: 'setMaxUploadRetryTime()',
279+
setMaxDownloadRetryTime: 'setMaxDownloadRetryTime()',
280+
},
281+
StorageReference: {
282+
delete: 'deleteObject()',
283+
getDownloadURL: 'getDownloadURL()',
284+
getMetadata: 'getMetadata()',
285+
list: 'list()',
286+
listAll: 'listAll()',
287+
updateMetadata: 'updateMetadata()',
288+
put: 'uploadBytesResumable()',
289+
putString: 'uploadString()',
290+
putFile: 'putFile()',
291+
writeToFile: 'writeToFile()',
292+
toString: 'toString()',
293+
child: 'child()',
294+
},
295+
statics: {
296+
StringFormat: 'StringFormat',
297+
TaskEvent: 'TaskEvent',
298+
TaskState: 'TaskState',
299+
},
300+
},
272301
};
273302

274303
const modularDeprecationMessage =
@@ -332,6 +361,10 @@ function getNamespace(target) {
332361
if (target._config && target._config.namespace) {
333362
return target._config.namespace;
334363
}
364+
if (target.constructor.name === 'StorageReference') {
365+
return 'storage';
366+
}
367+
335368
const className = target.name ? target.name : target.constructor.name;
336369
return Object.keys(mapOfDeprecationReplacements).find(key => {
337370
if (mapOfDeprecationReplacements[key][className]) {
@@ -349,6 +382,11 @@ function getInstanceName(target) {
349382
// module class instance, we use default to store map of deprecated methods
350383
return 'default';
351384
}
385+
386+
if (target.constructor.name === 'StorageReference') {
387+
// if path passed into ref(), it will pass in the arg as target.name
388+
return target.constructor.name;
389+
}
352390
if (target.name) {
353391
// It's a function which has a name property unlike classes
354392
return target.name;
@@ -390,6 +428,9 @@ export function createDeprecationProxy(instance) {
390428
if (prop === 'CustomProvider') {
391429
deprecationConsoleWarning('appCheck', prop, 'statics', false);
392430
}
431+
if (prop === 'StringFormat' || prop === 'TaskEvent' || prop === 'TaskState') {
432+
deprecationConsoleWarning('storage', prop, 'statics', false);
433+
}
393434

394435
if (prop !== 'setLogLevel') {
395436
// we want to capture setLogLevel function call which we do below

packages/storage/__tests__/storage.test.ts

Lines changed: 252 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
1+
import { afterAll, beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals';
22

33
import storage, {
44
firebase,
@@ -30,6 +30,14 @@ import storage, {
3030
TaskState,
3131
} from '../lib';
3232

33+
import {
34+
createCheckV9Deprecation,
35+
CheckV9DeprecationFunction,
36+
} from '../../app/lib/common/unitTestUtils';
37+
38+
// @ts-ignore test
39+
import FirebaseModule from '../../app/lib/internal/FirebaseModule';
40+
3341
describe('Storage', function () {
3442
describe('namespace', function () {
3543
beforeAll(async function () {
@@ -196,4 +204,247 @@ describe('Storage', function () {
196204
expect(TaskState.SUCCESS).toBeDefined();
197205
});
198206
});
207+
208+
describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () {
209+
let storageV9Deprecation: CheckV9DeprecationFunction;
210+
let storageRefV9Deprecation: CheckV9DeprecationFunction;
211+
let staticsV9Deprecation: CheckV9DeprecationFunction;
212+
213+
beforeEach(function () {
214+
storageV9Deprecation = createCheckV9Deprecation(['storage']);
215+
216+
storageRefV9Deprecation = createCheckV9Deprecation(['storage', 'StorageReference']);
217+
218+
staticsV9Deprecation = createCheckV9Deprecation(['storage', 'statics']);
219+
220+
// @ts-ignore test
221+
jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => {
222+
return new Proxy(
223+
{},
224+
{
225+
get: (_target, prop) => {
226+
// Handle list operations specially
227+
if (prop === 'list' || prop === 'listAll') {
228+
return jest.fn().mockResolvedValue({
229+
items: [],
230+
prefixes: [],
231+
nextPageToken: null,
232+
} as never);
233+
}
234+
// Default mock for other operations
235+
return jest.fn().mockResolvedValue({
236+
source: 'cache',
237+
changes: [],
238+
documents: [],
239+
metadata: {},
240+
path: 'foo',
241+
} as never);
242+
},
243+
},
244+
);
245+
});
246+
});
247+
248+
describe('Storage', function () {
249+
it('useStorageEmulator()', function () {
250+
const storage = getStorage();
251+
storageV9Deprecation(
252+
() => connectStorageEmulator(storage, 'localhost', 8080),
253+
() => storage.useEmulator('localhost', 8080),
254+
'useEmulator',
255+
);
256+
});
257+
258+
it('ref()', function () {
259+
const storage = getStorage();
260+
storageV9Deprecation(
261+
() => ref(storage, 'foo'),
262+
() => storage.ref('foo'),
263+
'ref',
264+
);
265+
});
266+
267+
it('refFromURL()', function () {
268+
const storage = firebase.app().storage();
269+
storageV9Deprecation(
270+
() => refFromURL(storage, 'gs://flutterfire-e2e-tests.appspot.com/flutter-tsts'),
271+
() => storage.refFromURL('gs://flutterfire-e2e-tests.appspot.com/flutter-tsts'),
272+
'refFromURL',
273+
);
274+
});
275+
276+
it('setMaxOperationRetryTime()', function () {
277+
const storage = firebase.app().storage();
278+
storageV9Deprecation(
279+
() => setMaxOperationRetryTime(storage, 1000),
280+
() => storage.setMaxOperationRetryTime(1000),
281+
'setMaxOperationRetryTime',
282+
);
283+
});
284+
285+
it('setMaxUploadRetryTime()', function () {
286+
const storage = firebase.app().storage();
287+
storageV9Deprecation(
288+
() => setMaxUploadRetryTime(storage, 1000),
289+
() => storage.setMaxUploadRetryTime(1000),
290+
'setMaxUploadRetryTime',
291+
);
292+
});
293+
294+
it('setMaxDownloadRetryTime()', function () {
295+
const storage = firebase.app().storage();
296+
storageV9Deprecation(
297+
() => setMaxDownloadRetryTime(storage, 1000),
298+
() => storage.setMaxDownloadRetryTime(1000),
299+
'setMaxDownloadRetryTime',
300+
);
301+
});
302+
303+
it('delete()', function () {
304+
const storage = firebase.app().storage();
305+
const storageRef = storage.ref('foo');
306+
storageRefV9Deprecation(
307+
() => deleteObject(storageRef),
308+
() => storageRef.delete(),
309+
'delete',
310+
);
311+
});
312+
313+
it('getDownloadURL()', function () {
314+
const storage = firebase.app().storage();
315+
const storageRef = storage.ref('foo');
316+
storageRefV9Deprecation(
317+
() => getDownloadURL(storageRef),
318+
() => storageRef.getDownloadURL(),
319+
'getDownloadURL',
320+
);
321+
});
322+
323+
it('getMetadata()', function () {
324+
const storage = firebase.app().storage();
325+
const storageRef = storage.ref('foo');
326+
storageRefV9Deprecation(
327+
() => getMetadata(storageRef),
328+
() => storageRef.getMetadata(),
329+
'getMetadata',
330+
);
331+
});
332+
333+
it('list()', function () {
334+
const storage = firebase.app().storage();
335+
const storageRef = storage.ref('foo');
336+
storageRefV9Deprecation(
337+
() => list(storageRef),
338+
() => storageRef.list(),
339+
'list',
340+
);
341+
});
342+
343+
it('listAll()', function () {
344+
const storage = firebase.app().storage();
345+
const storageRef = storage.ref('foo');
346+
storageRefV9Deprecation(
347+
() => listAll(storageRef),
348+
() => storageRef.listAll(),
349+
'listAll',
350+
);
351+
});
352+
353+
it('updateMetadata()', function () {
354+
const storage = firebase.app().storage();
355+
const storageRef = storage.ref('foo');
356+
storageRefV9Deprecation(
357+
() => updateMetadata(storageRef, {}),
358+
() => storageRef.updateMetadata({}),
359+
'updateMetadata',
360+
);
361+
});
362+
363+
it('put()', function () {
364+
const storage = firebase.app().storage();
365+
const storageRef = storage.ref('foo');
366+
storageRefV9Deprecation(
367+
() => uploadBytesResumable(storageRef, new Blob(['foo']), {}),
368+
() => storageRef.put(new Blob(['foo']), {}),
369+
'put',
370+
);
371+
});
372+
373+
it('putString()', function () {
374+
const storage = firebase.app().storage();
375+
const storageRef = storage.ref('foo');
376+
storageRefV9Deprecation(
377+
() => uploadString(storageRef, 'foo', StringFormat.RAW),
378+
() => storageRef.putString('foo', StringFormat.RAW),
379+
'putString',
380+
);
381+
});
382+
383+
it('putFile()', function () {
384+
const storage = firebase.app().storage();
385+
const storageRef = storage.ref('foo');
386+
storageRefV9Deprecation(
387+
() => putFile(storageRef, 'foo', {}),
388+
() => storageRef.putFile('foo', {}),
389+
'putFile',
390+
);
391+
});
392+
393+
it('writeToFile()', function () {
394+
const storage = firebase.app().storage();
395+
const storageRef = storage.ref('foo');
396+
storageRefV9Deprecation(
397+
() => writeToFile(storageRef, 'foo'),
398+
() => storageRef.writeToFile('foo'),
399+
'writeToFile',
400+
);
401+
});
402+
403+
it('toString()', function () {
404+
const storage = firebase.app().storage();
405+
const storageRef = storage.ref('foo');
406+
storageRefV9Deprecation(
407+
() => toString(storageRef),
408+
() => storageRef.toString(),
409+
'toString',
410+
);
411+
});
412+
413+
it('child()', function () {
414+
const storage = firebase.app().storage();
415+
const storageRef = storage.ref('foo');
416+
storageRefV9Deprecation(
417+
() => child(storageRef, 'bar'),
418+
() => storageRef.child('bar'),
419+
'child',
420+
);
421+
});
422+
});
423+
424+
describe('statics', function () {
425+
it('StringFormat static', function () {
426+
staticsV9Deprecation(
427+
() => StringFormat.RAW,
428+
() => firebase.storage.StringFormat.RAW,
429+
'StringFormat',
430+
);
431+
});
432+
433+
it('TaskEvent static', function () {
434+
staticsV9Deprecation(
435+
() => TaskEvent.STATE_CHANGED,
436+
() => firebase.storage.TaskEvent.STATE_CHANGED,
437+
'TaskEvent',
438+
);
439+
});
440+
441+
it('TaskState static', function () {
442+
staticsV9Deprecation(
443+
() => TaskState.SUCCESS,
444+
() => firebase.storage.TaskState.SUCCESS,
445+
'TaskState',
446+
);
447+
});
448+
});
449+
});
199450
});

packages/storage/e2e/StorageReference.e2e.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ describe('storage() -> StorageReference', function () {
110110
const storageReference = firebase.storage().ref(`${PATH}/deleteMe.txt`);
111111
await storageReference.putString('Delete File');
112112
await storageReference.delete();
113-
114113
try {
115114
await storageReference.getMetadata();
116115
return Promise.reject(new Error('Did not throw'));
@@ -717,16 +716,16 @@ describe('storage() -> StorageReference', function () {
717716
// Same bucket defined in app.js when setting up emulator
718717

719718
it('should write a file to the second storage bucket', async function () {
720-
const { ref } = storageModular;
719+
const { ref, uploadString } = storageModular;
721720

722721
// "only-second-bucket" is not an allowable path on live project for either bucket
723722
const storageReference = ref(secondStorage, 'only-second-bucket/ok.txt');
724723

725-
await storageReference.putString('Hello World');
724+
await uploadString(storageReference, 'Hello World');
726725
});
727726

728727
it('should throw exception on path not allowed on second bucket security rules', async function () {
729-
const { ref } = storageModular;
728+
const { ref, uploadString } = storageModular;
730729

731730
// "react-native-firebase-testing" is not an allowed on second bucket, only "ony-second-bucket"
732731
const storageReference = ref(
@@ -735,7 +734,7 @@ describe('storage() -> StorageReference', function () {
735734
);
736735

737736
try {
738-
await storageReference.putString('Hello World');
737+
await uploadString(storageReference, 'Hello World');
739738
return Promise.reject(new Error('Did not throw'));
740739
} catch (error) {
741740
error.code.should.equal('storage/unauthorized');
@@ -974,10 +973,10 @@ describe('storage() -> StorageReference', function () {
974973

975974
describe('list', function () {
976975
it('should return list results', async function () {
977-
const { getStorage, ref } = storageModular;
976+
const { getStorage, ref, list } = storageModular;
978977
const storageReference = ref(getStorage(), `${PATH}/list`);
979978

980-
const result = await storageReference.list();
979+
const result = await list(storageReference);
981980

982981
result.constructor.name.should.eql('StorageListResult');
983982
result.should.have.property('nextPageToken');

0 commit comments

Comments
 (0)