Skip to content

Implement functions and storage compat interop #4639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 1, 2021
11 changes: 8 additions & 3 deletions packages-exp/functions-exp/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
useFunctionsEmulator as _useFunctionsEmulator,
httpsCallable as _httpsCallable
} from './service';
import { getModularInstance } from '@firebase/util';

export * from './public-types';

Expand All @@ -43,7 +44,7 @@ export function getFunctions(
): Functions {
// Dependencies
const functionsProvider: Provider<'functions-exp'> = _getProvider(
app,
getModularInstance(app),
FUNCTIONS_TYPE
);
const functionsInstance = functionsProvider.getImmediate({
Expand All @@ -66,7 +67,11 @@ export function useFunctionsEmulator(
host: string,
port: number
): void {
_useFunctionsEmulator(functionsInstance as FunctionsService, host, port);
_useFunctionsEmulator(
getModularInstance<FunctionsService>(functionsInstance as FunctionsService),
host,
port
);
}

/**
Expand All @@ -80,7 +85,7 @@ export function httpsCallable<RequestData = unknown, ResponseData = unknown>(
options?: HttpsCallableOptions
): HttpsCallable<RequestData, ResponseData> {
return _httpsCallable<RequestData, ResponseData>(
functionsInstance as FunctionsService,
getModularInstance<FunctionsService>(functionsInstance as FunctionsService),
name,
options
);
Expand Down
13 changes: 12 additions & 1 deletion packages/storage/exp/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
_getChild as _getChildInternal
} from '../src/reference';
import { STORAGE_TYPE } from './constants';
import { getModularInstance } from '@firebase/util';

/**
* Public types.
Expand All @@ -78,6 +79,7 @@ export function uploadBytes(
data: Blob | Uint8Array | ArrayBuffer,
metadata?: UploadMetadata
): Promise<UploadResult> {
ref = getModularInstance(ref);
return uploadBytesInternal(
ref as Reference,
data,
Expand All @@ -101,6 +103,7 @@ export function uploadString(
format?: string,
metadata?: UploadMetadata
): Promise<UploadResult> {
ref = getModularInstance(ref);
return uploadStringInternal(
ref as Reference,
value,
Expand All @@ -123,6 +126,7 @@ export function uploadBytesResumable(
data: Blob | Uint8Array | ArrayBuffer,
metadata?: UploadMetadata
): UploadTask {
ref = getModularInstance(ref);
return uploadBytesResumableInternal(
ref as Reference,
data,
Expand All @@ -138,6 +142,7 @@ export function uploadBytesResumable(
* @param ref - StorageReference to get metadata from.
*/
export function getMetadata(ref: StorageReference): Promise<FullMetadata> {
ref = getModularInstance(ref);
return getMetadataInternal(ref as Reference) as Promise<FullMetadata>;
}

Expand All @@ -154,6 +159,7 @@ export function updateMetadata(
ref: StorageReference,
metadata: SettableMetadata
): Promise<FullMetadata> {
ref = getModularInstance(ref);
return updateMetadataInternal(
ref as Reference,
metadata as Partial<MetadataInternal>
Expand Down Expand Up @@ -186,6 +192,7 @@ export function list(
ref: StorageReference,
options?: ListOptions
): Promise<ListResult> {
ref = getModularInstance(ref);
return listInternal(ref as Reference, options);
}

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

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

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

Expand All @@ -255,6 +265,7 @@ export function ref(
serviceOrRef: StorageService | StorageReference,
pathOrUrl?: string
): StorageReference | null {
serviceOrRef = getModularInstance(serviceOrRef);
return refInternal(
serviceOrRef as StorageServiceInternal | Reference,
pathOrUrl
Expand Down Expand Up @@ -282,7 +293,7 @@ export function getStorage(
app: FirebaseApp,
bucketUrl?: string
): StorageService {
// Dependencies
app = getModularInstance(app);
const storageProvider: Provider<'storage-exp'> = _getProvider(
app,
STORAGE_TYPE
Expand Down