Skip to content

Add url param to getStorage and update public Metadata types #4340

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 4 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions common/api-review/storage.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

import { FirebaseApp } from '@firebase/app';
import { FirebaseStorageError } from '@firebase/storage-types/exp';
import { FullMetadata } from '@firebase/storage-types/exp';
import { ListOptions } from '@firebase/storage-types/exp';
import { ListResult } from '@firebase/storage-types/exp';
import { Metadata } from '@firebase/storage-types/exp';
import { SettableMetadata } from '@firebase/storage-types/exp';
import { StorageObserver } from '@firebase/storage-types/exp';
import { StorageReference } from '@firebase/storage-types/exp';
import { StorageService } from '@firebase/storage-types/exp';
import { TaskEvent } from '@firebase/storage-types/exp';
import { TaskState } from '@firebase/storage-types/exp';
import { UploadMetadata } from '@firebase/storage-types/exp';
import { UploadResult } from '@firebase/storage-types/exp';
import { UploadTask } from '@firebase/storage-types/exp';

Expand All @@ -22,14 +24,16 @@ export function deleteObject(ref: StorageReference): Promise<void>;

export { FirebaseStorageError }

export { FullMetadata }

// @public
export function getDownloadURL(ref: StorageReference): Promise<string>;

// @public
export function getMetadata(ref: StorageReference): Promise<Metadata>;
export function getMetadata(ref: StorageReference): Promise<FullMetadata>;

// @public
export function getStorage(app: FirebaseApp): StorageService;
export function getStorage(app: FirebaseApp, url?: string): StorageService;

// @public
export function list(ref: StorageReference, options?: ListOptions): Promise<ListResult>;
Expand All @@ -41,14 +45,14 @@ export { ListOptions }

export { ListResult }

export { Metadata }

// @public
export function ref(storage: StorageService, url?: string): StorageReference;

// @public
export function ref(storageOrRef: StorageService | StorageReference, path?: string): StorageReference;

export { SettableMetadata }

export { StorageObserver }

export { StorageReference }
Expand All @@ -71,18 +75,20 @@ export { TaskEvent }
export { TaskState }

// @public
export function updateMetadata(ref: StorageReference, metadata: Partial<Metadata>): Promise<Metadata>;
export function updateMetadata(ref: StorageReference, metadata: SettableMetadata): Promise<FullMetadata>;

// @public
export function uploadBytes(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: Metadata): Promise<UploadResult>;
export function uploadBytes(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): Promise<UploadResult>;

// @public
export function uploadBytesResumable(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: Metadata): UploadTask;
export function uploadBytesResumable(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): UploadTask;

export { UploadMetadata }

export { UploadResult }

// @public
export function uploadString(ref: StorageReference, value: string, format?: string, metadata?: Metadata): Promise<UploadResult>;
export function uploadString(ref: StorageReference, value: string, format?: string, metadata?: UploadMetadata): Promise<UploadResult>;

export { UploadTask }

Expand Down
98 changes: 54 additions & 44 deletions packages/storage-types/exp/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,61 @@ export interface ListResult {
nextPageToken?: string;
}

/**
* Object metadata that can be set at any time.
* @public
*/
export interface SettableMetadata {
/**
* Served as the 'Cache-Control' header on object download.
*/
cacheControl?: string | undefined;

/**
* Served as the 'Content-Disposition' header on object download.
*/
contentDisposition?: string | undefined;

/**
* Served as the 'Content-Encoding' header on object download.
*/
contentEncoding?: string | undefined;

/**
* Served as the 'Content-Language' header on object download.
*/
contentLanguage?: string | undefined;

/**
* Served as the 'Content-Type' header on object download.
*/
contentType?: string | undefined;

/**
* Additional user-defined custom metadata.
*/
customMetadata?:
| {
[key: string]: string;
}
| undefined;
}
/**
* Object metadata that can be set at upload.
* @public
*/
export interface UploadMetadata extends SettableMetadata {
/**
* A Base64-encoded MD5 hash of the object being uploaded.
*/
md5Hash?: string | undefined;
}

/**
* The full set of object metadata, including read-only properties.
* @public
*/
export interface Metadata {
export interface FullMetadata extends UploadMetadata {
/**
* The bucket this object is contained in.
*/
Expand Down Expand Up @@ -168,55 +218,15 @@ export interface Metadata {
*/
updated: string;

/**
* A Base64-encoded MD5 hash of the object being uploaded.
*/
md5Hash: string | undefined;

/**
* Served as the 'Cache-Control' header on object download.
*/
cacheControl: string | undefined;

/**
* Served as the 'Content-Disposition' header on object download.
*/
contentDisposition: string | undefined;

/**
* Served as the 'Content-Encoding' header on object download.
*/
contentEncoding: string | undefined;

/**
* Served as the 'Content-Language' header on object download.
*/
contentLanguage: string | undefined;

/**
* Served as the 'Content-Type' header on object download.
*/
contentType: string | undefined;

/**
* Tokens to allow access to the downloatd URL.
*/
downloadTokens: string[] | undefined;

/**
* Additional user-defined custom metadata.
*/
customMetadata:
| {
[key: string]: string;
}
| undefined;

/**
* `StorageReference` associated with this upload.
*/
ref: StorageReference | undefined;
[prop: string]: unknown;
ref?: StorageReference | undefined;
}

/**
Expand Down Expand Up @@ -428,7 +438,7 @@ export interface UploadTaskSnapshot {
* Before the upload completes, contains the metadata sent to the server.
* After the upload completes, contains the metadata sent back from the server.
*/
metadata: Metadata;
metadata: FullMetadata;

/**
* The reference that spawned this snapshot's upload task.
Expand Down Expand Up @@ -459,7 +469,7 @@ export interface UploadResult {
/**
* Contains the metadata sent back from the server.
*/
readonly metadata: Metadata;
readonly metadata: FullMetadata;

/**
* The reference that spawned this upload.
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/compat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ registerStorage(firebase as _FirebaseNamespace);
declare module '@firebase/app-types' {
interface FirebaseNamespace {
storage?: {
(app?: FirebaseApp): types.FirebaseStorage;
(app?: FirebaseApp, url?: string): types.FirebaseStorage;
Storage: typeof types.FirebaseStorage;

StringFormat: {
Expand Down
17 changes: 11 additions & 6 deletions packages/storage/compat/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export class ReferenceCompat implements types.Reference {
*/
put(
data: Blob | Uint8Array | ArrayBuffer,
metadata?: Metadata
metadata?: types.FullMetadata
): types.UploadTask {
this._throwIfRoot('put');
return new UploadTaskCompat(
uploadBytesResumable(this._delegate, data, metadata),
uploadBytesResumable(this._delegate, data, metadata as Metadata),
this
);
}
Expand Down Expand Up @@ -182,8 +182,8 @@ export class ReferenceCompat implements types.Reference {
* object doesn't exist or metadata cannot be retreived, the promise is
* rejected.
*/
getMetadata(): Promise<Metadata> {
return getMetadata(this._delegate);
getMetadata(): Promise<types.FullMetadata> {
return getMetadata(this._delegate) as Promise<types.FullMetadata>;
}

/**
Expand All @@ -195,8 +195,13 @@ export class ReferenceCompat implements types.Reference {
* with the new metadata for this object.
* @see firebaseStorage.Reference.prototype.getMetadata
*/
updateMetadata(metadata: Metadata): Promise<Metadata> {
return updateMetadata(this._delegate, metadata);
updateMetadata(
metadata: types.SettableMetadata
): Promise<types.FullMetadata> {
return updateMetadata(
this._delegate,
metadata as Metadata
) as Promise<types.FullMetadata>;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions packages/storage/compat/tasksnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import * as types from '@firebase/storage-types';
import { ReferenceCompat } from './reference';
import { UploadTaskCompat } from './task';
import { UploadTaskSnapshot } from '../src/tasksnapshot';
import { Metadata } from '../src/metadata';

export class UploadTaskSnapshotCompat implements types.UploadTaskSnapshot {
constructor(
Expand All @@ -31,8 +30,8 @@ export class UploadTaskSnapshotCompat implements types.UploadTaskSnapshot {
get bytesTransferred(): number {
return this._delegate.bytesTransferred;
}
get metadata(): Metadata {
return this._delegate.metadata;
get metadata(): types.FullMetadata {
return this._delegate.metadata as types.FullMetadata;
}
get state(): string {
return this._delegate.state;
Expand Down
Loading