Skip to content

Commit 97d8fb5

Browse files
committed
Add url string arg and update metadata type
1 parent 352eb47 commit 97d8fb5

File tree

7 files changed

+207
-122
lines changed

7 files changed

+207
-122
lines changed

common/api-review/storage.api.md

Lines changed: 15 additions & 9 deletions
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

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -121,102 +121,112 @@ export interface ListResult {
121121
}
122122

123123
/**
124-
* The full set of object metadata, including read-only properties.
124+
* Object metadata that can be set at any time.
125125
* @public
126126
*/
127-
export interface Metadata {
127+
export interface SettableMetadata {
128128
/**
129-
* The bucket this object is contained in.
129+
* Served as the 'Cache-Control' header on object download.
130130
*/
131-
bucket: string;
131+
cacheControl?: string | undefined;
132132

133133
/**
134-
* The full path of this object.
134+
* Served as the 'Content-Disposition' header on object download.
135135
*/
136-
fullPath: string;
136+
contentDisposition?: string | undefined;
137137

138138
/**
139-
* The object's generation.
140-
* {@link https://cloud.google.com/storage/docs/generations-preconditions}
139+
* Served as the 'Content-Encoding' header on object download.
141140
*/
142-
generation: string;
141+
contentEncoding?: string | undefined;
143142

144143
/**
145-
* The object's metageneration.
146-
* {@link https://cloud.google.com/storage/docs/generations-preconditions}
144+
* Served as the 'Content-Language' header on object download.
147145
*/
148-
metageneration: string;
146+
contentLanguage?: string | undefined;
149147

150148
/**
151-
* The short name of this object, which is the last component of the full path.
152-
* For example, if fullPath is 'full/path/image.png', name is 'image.png'.
149+
* Served as the 'Content-Type' header on object download.
153150
*/
154-
name: string;
151+
contentType?: string | undefined;
155152

156153
/**
157-
* The size of this object, in bytes.
154+
* Additional user-defined custom metadata.
158155
*/
159-
size: number;
160-
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 {
161167
/**
162-
* A date string representing when this object was created.
168+
* A Base64-encoded MD5 hash of the object being uploaded.
163169
*/
164-
timeCreated: string;
170+
md5Hash?: string | undefined;
171+
}
165172

173+
/**
174+
* The full set of object metadata, including read-only properties.
175+
* @public
176+
*/
177+
export interface FullMetadata extends UploadMetadata {
166178
/**
167-
* A date string representing when this object was last updated.
179+
* The bucket this object is contained in.
168180
*/
169-
updated: string;
181+
bucket?: string;
170182

171183
/**
172-
* A Base64-encoded MD5 hash of the object being uploaded.
184+
* The full path of this object.
173185
*/
174-
md5Hash: string | undefined;
186+
fullPath?: string;
175187

176188
/**
177-
* Served as the 'Cache-Control' header on object download.
189+
* The object's generation.
190+
* {@link https://cloud.google.com/storage/docs/generations-preconditions}
178191
*/
179-
cacheControl: string | undefined;
192+
generation?: string;
180193

181194
/**
182-
* Served as the 'Content-Disposition' header on object download.
195+
* The object's metageneration.
196+
* {@link https://cloud.google.com/storage/docs/generations-preconditions}
183197
*/
184-
contentDisposition: string | undefined;
198+
metageneration?: string;
185199

186200
/**
187-
* Served as the 'Content-Encoding' header on object download.
201+
* The short name of this object, which is the last component of the full path.
202+
* For example, if fullPath is 'full/path/image.png', name is 'image.png'.
188203
*/
189-
contentEncoding: string | undefined;
204+
name?: string;
190205

191206
/**
192-
* Served as the 'Content-Language' header on object download.
207+
* The size of this object, in bytes.
193208
*/
194-
contentLanguage: string | undefined;
209+
size?: number;
195210

196211
/**
197-
* Served as the 'Content-Type' header on object download.
212+
* A date string representing when this object was created.
198213
*/
199-
contentType: string | undefined;
214+
timeCreated?: string;
200215

201216
/**
202-
* Tokens to allow access to the downloatd URL.
217+
* A date string representing when this object was last updated.
203218
*/
204-
downloadTokens: string[] | undefined;
219+
updated?: string;
205220

206221
/**
207-
* Additional user-defined custom metadata.
222+
* Tokens to allow access to the downloatd URL.
208223
*/
209-
customMetadata:
210-
| {
211-
[key: string]: string;
212-
}
213-
| undefined;
224+
downloadTokens?: string[] | undefined;
214225

215226
/**
216227
* `StorageReference` associated with this upload.
217228
*/
218-
ref: StorageReference | undefined;
219-
[prop: string]: unknown;
229+
ref?: StorageReference | undefined;
220230
}
221231

222232
/**

packages/storage/compat/index.ts

Lines changed: 1 addition & 1 deletion
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/exp/index.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ import { name, version } from '../package.json';
4141
import {
4242
StorageReference,
4343
StorageService,
44-
Metadata,
4544
UploadResult,
4645
ListOptions,
4746
ListResult,
4847
UploadTask,
4948
FirebaseStorageError,
5049
TaskEvent,
5150
TaskState,
52-
StorageObserver
51+
StorageObserver,
52+
SettableMetadata,
53+
UploadMetadata,
54+
FullMetadata
5355
} from '@firebase/storage-types/exp';
5456
import { Metadata as MetadataInternal } from '../src/metadata';
5557
import {
@@ -71,7 +73,9 @@ import {
7173
export {
7274
StorageReference,
7375
StorageService,
74-
Metadata,
76+
UploadMetadata,
77+
SettableMetadata,
78+
FullMetadata,
7579
UploadResult,
7680
ListOptions,
7781
ListResult,
@@ -88,13 +92,13 @@ export {
8892
* @public
8993
* @param ref - StorageReference where data should be uploaded.
9094
* @param data - The data to upload.
91-
* @param metadata - Metadata for the newly uploaded data.
95+
* @param metadata - Metadata for the data to upload.
9296
* @returns A Promise containing an UploadResult
9397
*/
9498
export function uploadBytes(
9599
ref: StorageReference,
96100
data: Blob | Uint8Array | ArrayBuffer,
97-
metadata?: Metadata
101+
metadata?: UploadMetadata
98102
): Promise<UploadResult> {
99103
return uploadBytesInternal(
100104
ref as Reference,
@@ -110,14 +114,14 @@ export function uploadBytes(
110114
* @param ref - StorageReference where string should be uploaded.
111115
* @param value - The string to upload.
112116
* @param format - The format of the string to upload.
113-
* @param metadata - Metadata for the newly uploaded string.
117+
* @param metadata - Metadata for the string to upload.
114118
* @returns A Promise containing an UploadResult
115119
*/
116120
export function uploadString(
117121
ref: StorageReference,
118122
value: string,
119123
format?: string,
120-
metadata?: Metadata
124+
metadata?: UploadMetadata
121125
): Promise<UploadResult> {
122126
return uploadStringInternal(
123127
ref as Reference,
@@ -133,13 +137,13 @@ export function uploadString(
133137
* @public
134138
* @param ref - StorageReference where data should be uploaded.
135139
* @param data - The data to upload.
136-
* @param metadata - Metadata for the newly uploaded data.
140+
* @param metadata - Metadata for the data to upload.
137141
* @returns An UploadTask
138142
*/
139143
export function uploadBytesResumable(
140144
ref: StorageReference,
141145
data: Blob | Uint8Array | ArrayBuffer,
142-
metadata?: Metadata
146+
metadata?: UploadMetadata
143147
): UploadTask {
144148
return uploadBytesResumableInternal(
145149
ref as Reference,
@@ -155,8 +159,8 @@ export function uploadBytesResumable(
155159
* @public
156160
* @param ref - StorageReference to get metadata from.
157161
*/
158-
export function getMetadata(ref: StorageReference): Promise<Metadata> {
159-
return getMetadataInternal(ref as Reference) as Promise<Metadata>;
162+
export function getMetadata(ref: StorageReference): Promise<FullMetadata> {
163+
return getMetadataInternal(ref as Reference) as Promise<FullMetadata>;
160164
}
161165

162166
/**
@@ -166,18 +170,16 @@ export function getMetadata(ref: StorageReference): Promise<Metadata> {
166170
* @param metadata - The new metadata for the object.
167171
* Only values that have been explicitly set will be changed. Explicitly
168172
* setting a value to null will remove the metadata.
169-
* @returns A promise that resolves
170-
* with the new metadata for this object.
171-
* See `firebaseStorage.Reference.prototype.getMetadata`
173+
* @returns A promise that resolves with the new metadata for this object.
172174
*/
173175
export function updateMetadata(
174176
ref: StorageReference,
175-
metadata: Partial<Metadata>
176-
): Promise<Metadata> {
177+
metadata: SettableMetadata
178+
): Promise<FullMetadata> {
177179
return updateMetadataInternal(
178180
ref as Reference,
179181
metadata as Partial<MetadataInternal>
180-
) as Promise<Metadata>;
182+
) as Promise<FullMetadata>;
181183
}
182184

183185
/**
@@ -294,13 +296,13 @@ const STORAGE_TYPE = 'storage-exp';
294296
* @param app - Firebase app to get Storage instance for.
295297
* @returns A Firebase StorageService instance.
296298
*/
297-
export function getStorage(app: FirebaseApp): StorageService {
299+
export function getStorage(app: FirebaseApp, url?: string): StorageService {
298300
// Dependencies
299301
const storageProvider: Provider<'storage-exp'> = _getProvider(
300302
app,
301303
STORAGE_TYPE
302304
);
303-
const storageInstance = storageProvider.getImmediate();
305+
const storageInstance = storageProvider.getImmediate({ identifier: url });
304306
return storageInstance;
305307
}
306308

0 commit comments

Comments
 (0)