Skip to content

Commit b28aff2

Browse files
authored
Add url param to getStorage and update public Metadata types (#4340)
1 parent 4190745 commit b28aff2

File tree

9 files changed

+221
-132
lines changed

9 files changed

+221
-132
lines changed

common/api-review/storage.api.md

+15-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
import { FirebaseApp } from '@firebase/app';
88
import { FirebaseStorageError } from '@firebase/storage-types/exp';
9+
import { FullMetadata } from '@firebase/storage-types/exp';
910
import { ListOptions } from '@firebase/storage-types/exp';
1011
import { ListResult } from '@firebase/storage-types/exp';
11-
import { Metadata } from '@firebase/storage-types/exp';
12+
import { SettableMetadata } from '@firebase/storage-types/exp';
1213
import { StorageObserver } from '@firebase/storage-types/exp';
1314
import { StorageReference } from '@firebase/storage-types/exp';
1415
import { StorageService } from '@firebase/storage-types/exp';
1516
import { TaskEvent } from '@firebase/storage-types/exp';
1617
import { TaskState } from '@firebase/storage-types/exp';
18+
import { UploadMetadata } from '@firebase/storage-types/exp';
1719
import { UploadResult } from '@firebase/storage-types/exp';
1820
import { UploadTask } from '@firebase/storage-types/exp';
1921

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

2325
export { FirebaseStorageError }
2426

27+
export { FullMetadata }
28+
2529
// @public
2630
export function getDownloadURL(ref: StorageReference): Promise<string>;
2731

2832
// @public
29-
export function getMetadata(ref: StorageReference): Promise<Metadata>;
33+
export function getMetadata(ref: StorageReference): Promise<FullMetadata>;
3034

3135
// @public
32-
export function getStorage(app: FirebaseApp): StorageService;
36+
export function getStorage(app: FirebaseApp, url?: string): StorageService;
3337

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

4246
export { ListResult }
4347

44-
export { Metadata }
45-
4648
// @public
4749
export function ref(storage: StorageService, url?: string): StorageReference;
4850

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

54+
export { SettableMetadata }
55+
5256
export { StorageObserver }
5357

5458
export { StorageReference }
@@ -71,18 +75,20 @@ export { TaskEvent }
7175
export { TaskState }
7276

7377
// @public
74-
export function updateMetadata(ref: StorageReference, metadata: Partial<Metadata>): Promise<Metadata>;
78+
export function updateMetadata(ref: StorageReference, metadata: SettableMetadata): Promise<FullMetadata>;
7579

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

7983
// @public
80-
export function uploadBytesResumable(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: Metadata): UploadTask;
84+
export function uploadBytesResumable(ref: StorageReference, data: Blob | Uint8Array | ArrayBuffer, metadata?: UploadMetadata): UploadTask;
85+
86+
export { UploadMetadata }
8187

8288
export { UploadResult }
8389

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

8793
export { UploadTask }
8894

packages/storage-types/exp/index.d.ts

+54-44
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,61 @@ export interface ListResult {
120120
nextPageToken?: string;
121121
}
122122

123+
/**
124+
* Object metadata that can be set at any time.
125+
* @public
126+
*/
127+
export interface SettableMetadata {
128+
/**
129+
* Served as the 'Cache-Control' header on object download.
130+
*/
131+
cacheControl?: string | undefined;
132+
133+
/**
134+
* Served as the 'Content-Disposition' header on object download.
135+
*/
136+
contentDisposition?: string | undefined;
137+
138+
/**
139+
* Served as the 'Content-Encoding' header on object download.
140+
*/
141+
contentEncoding?: string | undefined;
142+
143+
/**
144+
* Served as the 'Content-Language' header on object download.
145+
*/
146+
contentLanguage?: string | undefined;
147+
148+
/**
149+
* Served as the 'Content-Type' header on object download.
150+
*/
151+
contentType?: string | undefined;
152+
153+
/**
154+
* Additional user-defined custom metadata.
155+
*/
156+
customMetadata?:
157+
| {
158+
[key: string]: string;
159+
}
160+
| undefined;
161+
}
162+
/**
163+
* Object metadata that can be set at upload.
164+
* @public
165+
*/
166+
export interface UploadMetadata extends SettableMetadata {
167+
/**
168+
* A Base64-encoded MD5 hash of the object being uploaded.
169+
*/
170+
md5Hash?: string | undefined;
171+
}
172+
123173
/**
124174
* The full set of object metadata, including read-only properties.
125175
* @public
126176
*/
127-
export interface Metadata {
177+
export interface FullMetadata extends UploadMetadata {
128178
/**
129179
* The bucket this object is contained in.
130180
*/
@@ -168,55 +218,15 @@ export interface Metadata {
168218
*/
169219
updated: string;
170220

171-
/**
172-
* A Base64-encoded MD5 hash of the object being uploaded.
173-
*/
174-
md5Hash: string | undefined;
175-
176-
/**
177-
* Served as the 'Cache-Control' header on object download.
178-
*/
179-
cacheControl: string | undefined;
180-
181-
/**
182-
* Served as the 'Content-Disposition' header on object download.
183-
*/
184-
contentDisposition: string | undefined;
185-
186-
/**
187-
* Served as the 'Content-Encoding' header on object download.
188-
*/
189-
contentEncoding: string | undefined;
190-
191-
/**
192-
* Served as the 'Content-Language' header on object download.
193-
*/
194-
contentLanguage: string | undefined;
195-
196-
/**
197-
* Served as the 'Content-Type' header on object download.
198-
*/
199-
contentType: string | undefined;
200-
201221
/**
202222
* Tokens to allow access to the downloatd URL.
203223
*/
204224
downloadTokens: string[] | undefined;
205225

206-
/**
207-
* Additional user-defined custom metadata.
208-
*/
209-
customMetadata:
210-
| {
211-
[key: string]: string;
212-
}
213-
| undefined;
214-
215226
/**
216227
* `StorageReference` associated with this upload.
217228
*/
218-
ref: StorageReference | undefined;
219-
[prop: string]: unknown;
229+
ref?: StorageReference | undefined;
220230
}
221231

222232
/**
@@ -428,7 +438,7 @@ export interface UploadTaskSnapshot {
428438
* Before the upload completes, contains the metadata sent to the server.
429439
* After the upload completes, contains the metadata sent back from the server.
430440
*/
431-
metadata: Metadata;
441+
metadata: FullMetadata;
432442

433443
/**
434444
* The reference that spawned this snapshot's upload task.
@@ -459,7 +469,7 @@ export interface UploadResult {
459469
/**
460470
* Contains the metadata sent back from the server.
461471
*/
462-
readonly metadata: Metadata;
472+
readonly metadata: FullMetadata;
463473

464474
/**
465475
* The reference that spawned this upload.

packages/storage/compat/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ registerStorage(firebase as _FirebaseNamespace);
8888
declare module '@firebase/app-types' {
8989
interface FirebaseNamespace {
9090
storage?: {
91-
(app?: FirebaseApp): types.FirebaseStorage;
91+
(app?: FirebaseApp, url?: string): types.FirebaseStorage;
9292
Storage: typeof types.FirebaseStorage;
9393

9494
StringFormat: {

packages/storage/compat/reference.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ export class ReferenceCompat implements types.Reference {
9292
*/
9393
put(
9494
data: Blob | Uint8Array | ArrayBuffer,
95-
metadata?: Metadata
95+
metadata?: types.FullMetadata
9696
): types.UploadTask {
9797
this._throwIfRoot('put');
9898
return new UploadTaskCompat(
99-
uploadBytesResumable(this._delegate, data, metadata),
99+
uploadBytesResumable(this._delegate, data, metadata as Metadata),
100100
this
101101
);
102102
}
@@ -182,8 +182,8 @@ export class ReferenceCompat implements types.Reference {
182182
* object doesn't exist or metadata cannot be retreived, the promise is
183183
* rejected.
184184
*/
185-
getMetadata(): Promise<Metadata> {
186-
return getMetadata(this._delegate);
185+
getMetadata(): Promise<types.FullMetadata> {
186+
return getMetadata(this._delegate) as Promise<types.FullMetadata>;
187187
}
188188

189189
/**
@@ -195,8 +195,13 @@ export class ReferenceCompat implements types.Reference {
195195
* with the new metadata for this object.
196196
* @see firebaseStorage.Reference.prototype.getMetadata
197197
*/
198-
updateMetadata(metadata: Metadata): Promise<Metadata> {
199-
return updateMetadata(this._delegate, metadata);
198+
updateMetadata(
199+
metadata: types.SettableMetadata
200+
): Promise<types.FullMetadata> {
201+
return updateMetadata(
202+
this._delegate,
203+
metadata as Metadata
204+
) as Promise<types.FullMetadata>;
200205
}
201206

202207
/**

packages/storage/compat/tasksnapshot.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import * as types from '@firebase/storage-types';
1919
import { ReferenceCompat } from './reference';
2020
import { UploadTaskCompat } from './task';
2121
import { UploadTaskSnapshot } from '../src/tasksnapshot';
22-
import { Metadata } from '../src/metadata';
2322

2423
export class UploadTaskSnapshotCompat implements types.UploadTaskSnapshot {
2524
constructor(
@@ -31,8 +30,8 @@ export class UploadTaskSnapshotCompat implements types.UploadTaskSnapshot {
3130
get bytesTransferred(): number {
3231
return this._delegate.bytesTransferred;
3332
}
34-
get metadata(): Metadata {
35-
return this._delegate.metadata;
33+
get metadata(): types.FullMetadata {
34+
return this._delegate.metadata as types.FullMetadata;
3635
}
3736
get state(): string {
3837
return this._delegate.state;

0 commit comments

Comments
 (0)