Skip to content

Commit 8a2fa65

Browse files
Review
1 parent 66a72cf commit 8a2fa65

File tree

4 files changed

+27
-58
lines changed

4 files changed

+27
-58
lines changed

packages/storage/src/implementation/metadata.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import * as type from './type';
2727
import * as UrlUtils from './url';
2828
import { Reference } from '../reference';
2929
import { StorageService } from '../service';
30-
import { Code, FirebaseStorageError } from './error';
3130

3231
export function noXform_<T>(metadata: Metadata, value: T): T {
3332
return value;
@@ -206,26 +205,3 @@ export function toResourceString(
206205
}
207206
return JSON.stringify(resource);
208207
}
209-
210-
export function validateMetadata(p: { [key: string]: unknown }): void {
211-
for (const key in p) {
212-
if (p.hasOwnProperty(key)) {
213-
const val = p[key];
214-
if (key === 'customMetadata') {
215-
if (!type.isObject(val)) {
216-
throw new FirebaseStorageError(
217-
Code.INVALID_ARGUMENT,
218-
"Expected object for 'customMetadata' mapping."
219-
);
220-
}
221-
} else {
222-
if (type.isNonNullObject(val)) {
223-
throw new FirebaseStorageError(
224-
Code.INVALID_ARGUMENT,
225-
"Mapping for '" + key + "' cannot be an object."
226-
);
227-
}
228-
}
229-
}
230-
}
231-
}

packages/storage/src/implementation/type.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { Code, FirebaseStorageError } from './error';
19+
1820
/**
1921
* @return False if the object is undefined or null, true otherwise.
2022
*/
@@ -31,16 +33,8 @@ export function isFunction(p: unknown): p is Function {
3133
return typeof p === 'function';
3234
}
3335

34-
export function isObject(p: unknown): p is { [key: string]: unknown } | null {
35-
return typeof p === 'object';
36-
}
37-
38-
export function isNonNullObject(p: unknown): p is object {
39-
return isObject(p) && p !== null;
40-
}
41-
4236
export function isNonArrayObject(p: unknown): boolean {
43-
return isObject(p) && !Array.isArray(p);
37+
return typeof p === 'object' && !Array.isArray(p);
4438
}
4539

4640
export function isString(p: unknown): p is string {
@@ -54,3 +48,23 @@ export function isNativeBlob(p: unknown): p is Blob {
5448
export function isNativeBlobDefined(): boolean {
5549
return typeof Blob !== 'undefined';
5650
}
51+
52+
export function validateNumber(
53+
argument: string,
54+
minValue: number,
55+
maxValue: number,
56+
value: number
57+
): void {
58+
if (value < minValue) {
59+
throw new FirebaseStorageError(
60+
Code.INVALID_ARGUMENT,
61+
`Invalid value for '${argument}'. Expected ${minValue} or greater.`
62+
);
63+
}
64+
if (value > maxValue) {
65+
throw new FirebaseStorageError(
66+
Code.INVALID_ARGUMENT,
67+
`Invalid value for '${argument}'. Expected ${maxValue} or less.`
68+
);
69+
}
70+
}

packages/storage/src/reference.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ import { Location } from './implementation/location';
2424
import * as metadata from './implementation/metadata';
2525
import * as path from './implementation/path';
2626
import * as requests from './implementation/requests';
27-
import { StringFormat, dataFromString } from './implementation/string';
27+
import { dataFromString, StringFormat } from './implementation/string';
2828
import * as type from './implementation/type';
29+
import { validateNumber } from './implementation/type';
2930
import { Metadata } from './metadata';
3031
import { StorageService } from './service';
3132
import { UploadTask } from './task';
3233
import { ListOptions, ListResult } from './list';
33-
import { Code, FirebaseStorageError } from './implementation/error';
34-
import { validateMetadata } from './implementation/metadata';
3534

3635
/**
3736
* Provides methods to interact with a bucket in the Firebase Storage service.
@@ -295,7 +294,6 @@ export class Reference {
295294
* @see firebaseStorage.Reference.prototype.getMetadata
296295
*/
297296
updateMetadata(metadata: Metadata): Promise<Metadata> {
298-
validateMetadata(metadata);
299297
this.throwIfRoot_('updateMetadata');
300298
return this.service.getAuthToken().then(authToken => {
301299
const requestInfo = requests.updateMetadata(
@@ -338,23 +336,3 @@ export class Reference {
338336
}
339337
}
340338
}
341-
342-
export function validateNumber(
343-
argument: string,
344-
minValue: number,
345-
maxValue: number,
346-
value: number
347-
): void {
348-
if (value < minValue) {
349-
throw new FirebaseStorageError(
350-
Code.INVALID_ARGUMENT,
351-
`Invalid value for '${argument}'. Expected ${minValue} or greater.`
352-
);
353-
}
354-
if (value > maxValue) {
355-
throw new FirebaseStorageError(
356-
Code.INVALID_ARGUMENT,
357-
`Invalid value for '${argument}'. Expected ${maxValue} or less.`
358-
);
359-
}
360-
}

packages/storage/src/service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import { FailRequest } from './implementation/failrequest';
2121
import { Request, makeRequest } from './implementation/request';
2222
import { RequestInfo } from './implementation/requestinfo';
2323
import { XhrIoPool } from './implementation/xhriopool';
24-
import { Reference, validateNumber } from './reference';
24+
import { Reference } from './reference';
2525
import { Provider } from '@firebase/component';
2626
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
2727
import { FirebaseOptions } from '@firebase/app-types-exp';
2828
import * as constants from '../src/implementation/constants';
2929
import * as errorsExports from './implementation/error';
3030
import { Code, FirebaseStorageError } from './implementation/error';
31+
import { validateNumber } from './implementation/type';
3132

3233
/**
3334
* A service that provides firebaseStorage.Reference instances.

0 commit comments

Comments
 (0)