Skip to content

Commit b374636

Browse files
authored
Implement functions and storage compat interop (#4639)
1 parent ecdc5a0 commit b374636

File tree

2 files changed

+20
-4
lines changed
  • packages/storage/exp
  • packages-exp/functions-exp/src

2 files changed

+20
-4
lines changed

packages-exp/functions-exp/src/api.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
useFunctionsEmulator as _useFunctionsEmulator,
2727
httpsCallable as _httpsCallable
2828
} from './service';
29+
import { getModularInstance } from '@firebase/util';
2930

3031
export * from './public-types';
3132

@@ -43,7 +44,7 @@ export function getFunctions(
4344
): Functions {
4445
// Dependencies
4546
const functionsProvider: Provider<'functions-exp'> = _getProvider(
46-
app,
47+
getModularInstance(app),
4748
FUNCTIONS_TYPE
4849
);
4950
const functionsInstance = functionsProvider.getImmediate({
@@ -66,7 +67,11 @@ export function useFunctionsEmulator(
6667
host: string,
6768
port: number
6869
): void {
69-
_useFunctionsEmulator(functionsInstance as FunctionsService, host, port);
70+
_useFunctionsEmulator(
71+
getModularInstance<FunctionsService>(functionsInstance as FunctionsService),
72+
host,
73+
port
74+
);
7075
}
7176

7277
/**
@@ -80,7 +85,7 @@ export function httpsCallable<RequestData = unknown, ResponseData = unknown>(
8085
options?: HttpsCallableOptions
8186
): HttpsCallable<RequestData, ResponseData> {
8287
return _httpsCallable<RequestData, ResponseData>(
83-
functionsInstance as FunctionsService,
88+
getModularInstance<FunctionsService>(functionsInstance as FunctionsService),
8489
name,
8590
options
8691
);

packages/storage/exp/api.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
_getChild as _getChildInternal
5454
} from '../src/reference';
5555
import { STORAGE_TYPE } from './constants';
56+
import { getModularInstance } from '@firebase/util';
5657

5758
/**
5859
* Public types.
@@ -78,6 +79,7 @@ export function uploadBytes(
7879
data: Blob | Uint8Array | ArrayBuffer,
7980
metadata?: UploadMetadata
8081
): Promise<UploadResult> {
82+
ref = getModularInstance(ref);
8183
return uploadBytesInternal(
8284
ref as Reference,
8385
data,
@@ -101,6 +103,7 @@ export function uploadString(
101103
format?: string,
102104
metadata?: UploadMetadata
103105
): Promise<UploadResult> {
106+
ref = getModularInstance(ref);
104107
return uploadStringInternal(
105108
ref as Reference,
106109
value,
@@ -123,6 +126,7 @@ export function uploadBytesResumable(
123126
data: Blob | Uint8Array | ArrayBuffer,
124127
metadata?: UploadMetadata
125128
): UploadTask {
129+
ref = getModularInstance(ref);
126130
return uploadBytesResumableInternal(
127131
ref as Reference,
128132
data,
@@ -138,6 +142,7 @@ export function uploadBytesResumable(
138142
* @param ref - StorageReference to get metadata from.
139143
*/
140144
export function getMetadata(ref: StorageReference): Promise<FullMetadata> {
145+
ref = getModularInstance(ref);
141146
return getMetadataInternal(ref as Reference) as Promise<FullMetadata>;
142147
}
143148

@@ -154,6 +159,7 @@ export function updateMetadata(
154159
ref: StorageReference,
155160
metadata: SettableMetadata
156161
): Promise<FullMetadata> {
162+
ref = getModularInstance(ref);
157163
return updateMetadataInternal(
158164
ref as Reference,
159165
metadata as Partial<MetadataInternal>
@@ -186,6 +192,7 @@ export function list(
186192
ref: StorageReference,
187193
options?: ListOptions
188194
): Promise<ListResult> {
195+
ref = getModularInstance(ref);
189196
return listInternal(ref as Reference, options);
190197
}
191198

@@ -209,6 +216,7 @@ export function list(
209216
* folder. `nextPageToken` is never returned.
210217
*/
211218
export function listAll(ref: StorageReference): Promise<ListResult> {
219+
ref = getModularInstance(ref);
212220
return listAllInternal(ref as Reference);
213221
}
214222

@@ -219,6 +227,7 @@ export function listAll(ref: StorageReference): Promise<ListResult> {
219227
* URL for this object.
220228
*/
221229
export function getDownloadURL(ref: StorageReference): Promise<string> {
230+
ref = getModularInstance(ref);
222231
return getDownloadURLInternal(ref as Reference);
223232
}
224233

@@ -229,6 +238,7 @@ export function getDownloadURL(ref: StorageReference): Promise<string> {
229238
* @returns A promise that resolves if the deletion succeeds.
230239
*/
231240
export function deleteObject(ref: StorageReference): Promise<void> {
241+
ref = getModularInstance(ref);
232242
return deleteObjectInternal(ref as Reference);
233243
}
234244

@@ -255,6 +265,7 @@ export function ref(
255265
serviceOrRef: StorageService | StorageReference,
256266
pathOrUrl?: string
257267
): StorageReference | null {
268+
serviceOrRef = getModularInstance(serviceOrRef);
258269
return refInternal(
259270
serviceOrRef as StorageServiceInternal | Reference,
260271
pathOrUrl
@@ -282,7 +293,7 @@ export function getStorage(
282293
app: FirebaseApp,
283294
bucketUrl?: string
284295
): StorageService {
285-
// Dependencies
296+
app = getModularInstance(app);
286297
const storageProvider: Provider<'storage-exp'> = _getProvider(
287298
app,
288299
STORAGE_TYPE

0 commit comments

Comments
 (0)