Skip to content

Commit 3a82d4d

Browse files
committed
feat: Added @deprecated methods back in
1 parent 1a03111 commit 3a82d4d

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

src/misc/translate-from-firestore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const recursivelyMapStorageUrls = async (
103103
if (isFileField) {
104104
try {
105105
const src = await getDownloadURL(
106-
ref(fireWrapper.fireStorage(), fieldValue.src)
106+
ref(fireWrapper.storage(), fieldValue.src)
107107
);
108108
return {
109109
...fieldValue,

src/providers/database/firebase/FirebaseWrapper.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,35 @@ import { RAFirebaseOptions } from '../../options';
3939
import { IFirebaseWrapper } from './IFirebaseWrapper';
4040

4141
export class FirebaseWrapper implements IFirebaseWrapper {
42-
private readonly app: FireApp;
43-
private readonly firestore: FireStore;
44-
private readonly storage: FireStorage;
45-
private readonly auth: FireAuth;
42+
private readonly _app: FireApp;
43+
private readonly _firestore: FireStore;
44+
private readonly _storage: FireStorage;
45+
private readonly _auth: FireAuth;
4646
public options: RAFirebaseOptions;
4747

4848
constructor(inputOptions: RAFirebaseOptions | undefined, firebaseConfig: {}) {
4949
const optionsSafe = inputOptions || {};
5050
this.options = optionsSafe;
51-
this.app = (window as any)['_app'] = ObtainFirebaseApp(
51+
this._app = (window as any)['_app'] = ObtainFirebaseApp(
5252
firebaseConfig,
5353
optionsSafe
5454
);
55-
this.firestore = getFirestore(this.app);
56-
this.storage = getStorage(this.app);
57-
this.auth = getAuth(this.app);
55+
this._firestore = getFirestore(this._app);
56+
this._storage = getStorage(this._app);
57+
this._auth = getAuth(this._app);
5858
}
5959
dbGetCollection(absolutePath: string): FireStoreCollectionRef {
60-
return collection(this.firestore, absolutePath);
60+
return collection(this._firestore, absolutePath);
6161
}
6262
dbCreateBatch(): FireStoreBatch {
63-
return writeBatch(this.firestore);
63+
return writeBatch(this._firestore);
6464
}
6565
dbMakeNewId(): string {
66-
return doc(collection(this.firestore, 'collections')).id;
66+
return doc(collection(this._firestore, 'collections')).id;
6767
}
6868

6969
public OnUserLogout(callBack: (u: FireUser | null) => any) {
70-
this.auth.onAuthStateChanged((user) => {
70+
this._auth.onAuthStateChanged((user) => {
7171
const isLoggedOut = !user;
7272
log('FirebaseWrapper.OnUserLogout', { user, isLoggedOut });
7373
if (isLoggedOut) {
@@ -76,7 +76,7 @@ export class FirebaseWrapper implements IFirebaseWrapper {
7676
});
7777
}
7878
putFile(storagePath: string, rawFile: any): FireStoragePutFileResult {
79-
const task = uploadBytesResumable(ref(this.storage, storagePath), rawFile);
79+
const task = uploadBytesResumable(ref(this._storage, storagePath), rawFile);
8080
const taskResult = new Promise<FireUploadTaskSnapshot>((res, rej) =>
8181
task.then(res).catch(rej)
8282
);
@@ -92,7 +92,7 @@ export class FirebaseWrapper implements IFirebaseWrapper {
9292
};
9393
}
9494
async getStorageDownloadUrl(fieldSrc: string): Promise<string> {
95-
return getDownloadURL(ref(this.storage, fieldSrc));
95+
return getDownloadURL(ref(this._storage, fieldSrc));
9696
}
9797
public serverTimestamp() {
9898
// This line doesn't work for some reason, might be firebase sdk.
@@ -116,25 +116,25 @@ export class FirebaseWrapper implements IFirebaseWrapper {
116116

117117
log('setPersistence', { persistenceInput, persistenceResolved });
118118

119-
return this.auth
119+
return this._auth
120120
.setPersistence(persistenceResolved)
121121
.catch((error) => console.error(error));
122122
}
123123
async authSigninEmailPassword(
124124
email: string,
125125
password: string
126126
): Promise<FireAuthUserCredentials> {
127-
const user = await signInWithEmailAndPassword(this.auth, email, password);
127+
const user = await signInWithEmailAndPassword(this._auth, email, password);
128128
return user;
129129
}
130130
async authSignOut(): Promise<void> {
131-
return signOut(this.auth);
131+
return signOut(this._auth);
132132
}
133133
async authGetUserLoggedIn(): Promise<FireUser> {
134134
return new Promise((resolve, reject) => {
135-
const auth = this.auth;
135+
const auth = this._auth;
136136
if (auth.currentUser) return resolve(auth.currentUser);
137-
const unsubscribe = onAuthStateChanged(this.auth, (user) => {
137+
const unsubscribe = onAuthStateChanged(this._auth, (user) => {
138138
unsubscribe();
139139
if (user) {
140140
resolve(user);
@@ -149,17 +149,20 @@ export class FirebaseWrapper implements IFirebaseWrapper {
149149
}
150150

151151
/** @deprecated */
152-
public fireStorage(): FireStorage {
153-
return this.storage;
152+
public auth(): FireAuth {
153+
return this._auth;
154+
}
155+
/** @deprecated */
156+
public storage(): FireStorage {
157+
return this._storage;
154158
}
155-
156159
/** @deprecated */
157160
public GetApp(): FireApp {
158-
return this.app;
161+
return this._app;
159162
}
160163
/** @deprecated */
161164
public db(): FireStore {
162-
return this.firestore;
165+
return this._firestore;
163166
}
164167
}
165168

src/providers/database/firebase/IFirebaseWrapper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import firebase from 'firebase/compat';
22
import {
33
FireApp,
4+
FireAuth,
45
FireAuthUserCredentials,
56
FireStorage,
67
FireStoragePutFileResult,
@@ -35,8 +36,9 @@ export interface IFirebaseWrapper {
3536

3637
// Deprecated methods
3738
/** @deprecated */
38-
fireStorage(): FireStorage | firebase.storage.Storage;
39-
39+
auth(): FireAuth;
40+
/** @deprecated */
41+
storage(): FireStorage;
4042
/** @deprecated */
4143
db(): FireStore | firebase.firestore.Firestore;
4244
/** @deprecated */

tests/integration-tests/utils/FirebaseWrapperStub.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { getAuth } from 'firebase/auth';
12
import { collection, doc, writeBatch } from 'firebase/firestore';
23
import { getDownloadURL, ref, uploadBytesResumable } from 'firebase/storage';
34
import { RAFirebaseOptions } from '../../../src';
45
import {
56
FireApp,
7+
FireAuth,
68
FireAuthUserCredentials,
79
FireStorage,
810
FireStoragePutFileResult,
@@ -16,8 +18,8 @@ import { IFirebaseWrapper } from '../../../src/providers/database';
1618

1719
export class FirebaseWrapperStub implements IFirebaseWrapper {
1820
constructor(
19-
private firestore: FireStore | any,
20-
private storage: FireStorage,
21+
private _firestore: FireStore | any,
22+
private _storage: FireStorage,
2123
public options: RAFirebaseOptions
2224
) {}
2325

@@ -26,13 +28,13 @@ export class FirebaseWrapperStub implements IFirebaseWrapper {
2628
}
2729

2830
dbGetCollection(absolutePath: string): FireStoreCollectionRef {
29-
return collection(this.firestore, absolutePath);
31+
return collection(this._firestore, absolutePath);
3032
}
3133
dbCreateBatch(): FireStoreBatch {
32-
return writeBatch(this.firestore);
34+
return writeBatch(this._firestore);
3335
}
3436
dbMakeNewId(): string {
35-
return doc(collection(this.firestore, 'collections')).id;
37+
return doc(collection(this._firestore, 'collections')).id;
3638
}
3739

3840
// tslint:disable-next-line:no-empty
@@ -41,7 +43,7 @@ export class FirebaseWrapperStub implements IFirebaseWrapper {
4143
storagePath: string,
4244
rawFile: any
4345
): Promise<FireStoragePutFileResult> => {
44-
const task = uploadBytesResumable(ref(this.storage, storagePath), rawFile);
46+
const task = uploadBytesResumable(ref(this._storage, storagePath), rawFile);
4547
const taskResult = new Promise<FireUploadTaskSnapshot>((res, rej) =>
4648
task.then(res).catch(rej)
4749
);
@@ -55,7 +57,7 @@ export class FirebaseWrapperStub implements IFirebaseWrapper {
5557
};
5658
};
5759
async getStorageDownloadUrl(fieldSrc: string): Promise<string> {
58-
return getDownloadURL(ref(this.storage, fieldSrc));
60+
return getDownloadURL(ref(this._storage, fieldSrc));
5961
}
6062
authSetPersistence(
6163
persistenceInput: 'session' | 'local' | 'none'
@@ -81,12 +83,16 @@ export class FirebaseWrapperStub implements IFirebaseWrapper {
8183
// Deprecated methods
8284

8385
/** @deprecated */
84-
fireStorage(): FireStorage {
85-
return this.storage;
86+
auth(): FireAuth {
87+
return getAuth(this.GetApp());
88+
}
89+
/** @deprecated */
90+
storage(): FireStorage {
91+
return this._storage;
8692
}
8793
/** @deprecated */
8894
db(): FireStore {
89-
return this.firestore;
95+
return this._firestore;
9096
}
9197
/** @deprecated */
9298
GetUserLogin(): Promise<FireUser> {

0 commit comments

Comments
 (0)