Skip to content

Commit 98df69e

Browse files
committed
Address PR comments
1 parent dcbfc59 commit 98df69e

File tree

5 files changed

+21
-56
lines changed

5 files changed

+21
-56
lines changed

packages/storage/compat/task.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,21 @@ import { ReferenceCompat } from './reference';
3131
import { FirebaseStorageError } from '../src/implementation/error';
3232

3333
export class UploadTaskCompat implements types.UploadTask {
34+
private readonly _snapshot: UploadTaskSnapshotCompat;
3435
constructor(
3536
private readonly _delegate: UploadTask,
3637
private readonly _ref: ReferenceCompat
37-
) {}
38+
) {
39+
this._snapshot = new UploadTaskSnapshotCompat(
40+
this._delegate.snapshot,
41+
this,
42+
this._ref
43+
);
44+
}
3845

39-
snapshot = new UploadTaskSnapshotCompat(
40-
this._delegate.snapshot,
41-
this,
42-
this._ref
43-
);
46+
get snapshot(): UploadTaskSnapshotCompat {
47+
return this._snapshot;
48+
}
4449

4550
cancel = this._delegate.cancel.bind(this._delegate);
4651
catch = this._delegate.catch.bind(this._delegate);
@@ -73,21 +78,20 @@ export class UploadTaskCompat implements types.UploadTask {
7378
| StorageObserver<UploadTaskSnapshot>
7479
| undefined
7580
| ((a: UploadTaskSnapshot) => unknown) = undefined;
76-
if (nextOrObserver != null) {
81+
if (!!nextOrObserver) {
7782
if (typeof nextOrObserver === 'function') {
7883
wrappedNextOrObserver = (taskSnapshot: UploadTaskSnapshot) =>
7984
nextOrObserver(
8085
new UploadTaskSnapshotCompat(taskSnapshot, this, this._ref)
8186
);
8287
} else {
8388
wrappedNextOrObserver = {
84-
next:
85-
nextOrObserver.next == null
86-
? undefined
87-
: (taskSnapshot: UploadTaskSnapshot) =>
88-
nextOrObserver.next!(
89-
new UploadTaskSnapshotCompat(taskSnapshot, this, this._ref)
90-
),
89+
next: !!nextOrObserver.next
90+
? (taskSnapshot: UploadTaskSnapshot) =>
91+
nextOrObserver.next!(
92+
new UploadTaskSnapshotCompat(taskSnapshot, this, this._ref)
93+
)
94+
: undefined,
9195
complete: nextOrObserver.complete || undefined,
9296
error: nextOrObserver.error || undefined
9397
};

packages/storage/src/implementation/error.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -222,30 +222,8 @@ export function noDownloadURL(): FirebaseStorageError {
222222
);
223223
}
224224

225-
export function invalidArgument(message: string): FirebaseStorageError;
226-
export function invalidArgument(
227-
index: number,
228-
fnName: string,
229-
message: string
230-
): FirebaseStorageError;
231-
export function invalidArgument(
232-
indexOrMessage: number | string,
233-
fnName?: string,
234-
message?: string
235-
): FirebaseStorageError {
236-
if (typeof indexOrMessage === 'string') {
237-
return new FirebaseStorageError(Code.INVALID_ARGUMENT, indexOrMessage);
238-
} else {
239-
return new FirebaseStorageError(
240-
Code.INVALID_ARGUMENT,
241-
'Invalid argument in `' +
242-
fnName +
243-
'` at index ' +
244-
indexOrMessage +
245-
': ' +
246-
message
247-
);
248-
}
225+
export function invalidArgument(message: string): FirebaseStorageError {
226+
return new FirebaseStorageError(Code.INVALID_ARGUMENT, message);
249227
}
250228

251229
export function invalidArgumentCount(

packages/storage/src/implementation/location.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
import { invalidDefaultBucket, invalidUrl } from './error';
2424
import { DEFAULT_HOST } from './constants';
2525

26-
/**
27-
* @public
28-
*/
2926
export class Location {
3027
private path_: string;
3128

packages/storage/src/implementation/string.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export const StringFormat = {
2828
DATA_URL: 'data_url'
2929
};
3030

31-
/**
32-
* @internal
33-
*/
3431
export class StringData {
3532
contentType: string | null;
3633

packages/storage/src/reference.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ import { Metadata } from './metadata';
3535
import { StorageService } from './service';
3636
import { ListOptions, ListResult } from './list';
3737
import { UploadTask } from './task';
38-
import {
39-
invalidArgument,
40-
invalidRootOperation,
41-
noDownloadURL
42-
} from './implementation/error';
38+
import { invalidRootOperation, noDownloadURL } from './implementation/error';
4339
import { validateNumber } from './implementation/type';
4440

4541
/**
@@ -155,13 +151,6 @@ export function uploadString(
155151
format: StringFormat = StringFormat.RAW,
156152
metadata?: Metadata
157153
): UploadTask {
158-
if (typeof value !== 'string') {
159-
throw invalidArgument(
160-
1,
161-
'uploadString',
162-
'Must provide a string to upload.'
163-
);
164-
}
165154
ref._throwIfRoot('putString');
166155
const data = dataFromString(format, value);
167156
const metadataClone = { ...metadata } as Metadata;

0 commit comments

Comments
 (0)