Skip to content

Commit 8cd023c

Browse files
Remove JS input validation for Storage
1 parent eded218 commit 8cd023c

File tree

11 files changed

+85
-792
lines changed

11 files changed

+85
-792
lines changed

packages/storage/src/implementation/args.ts

Lines changed: 0 additions & 165 deletions
This file was deleted.

packages/storage/src/implementation/list.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121
import { Location } from './location';
2222
import * as json from './json';
23-
import * as type from './type';
2423
import { ListResult } from '../list';
2524
import { StorageService } from '../service';
2625

@@ -43,9 +42,6 @@ interface ListResultResponse {
4342
nextPageToken?: string;
4443
}
4544

46-
const MAX_RESULTS_KEY = 'maxResults';
47-
const MAX_MAX_RESULTS = 1000;
48-
const PAGE_TOKEN_KEY = 'pageToken';
4945
const PREFIXES_KEY = 'prefixes';
5046
const ITEMS_KEY = 'items';
5147

@@ -92,28 +88,3 @@ export function fromResponseString(
9288
const resource = (obj as unknown) as ListResultResponse;
9389
return fromBackendResponse(service, bucket, resource);
9490
}
95-
96-
export function listOptionsValidator(p: unknown): void {
97-
if (!type.isObject(p) || !p) {
98-
throw 'Expected ListOptions object.';
99-
}
100-
for (const key in p) {
101-
if (key === MAX_RESULTS_KEY) {
102-
if (
103-
!type.isInteger(p[MAX_RESULTS_KEY]) ||
104-
(p[MAX_RESULTS_KEY] as number) <= 0
105-
) {
106-
throw 'Expected maxResults to be a positive number.';
107-
}
108-
if ((p[MAX_RESULTS_KEY] as number) > 1000) {
109-
throw `Expected maxResults to be less than or equal to ${MAX_MAX_RESULTS}.`;
110-
}
111-
} else if (key === PAGE_TOKEN_KEY) {
112-
if (p[PAGE_TOKEN_KEY] && !type.isString(p[PAGE_TOKEN_KEY])) {
113-
throw 'Expected pageToken to be string.';
114-
}
115-
} else {
116-
throw 'Unknown option: ' + key;
117-
}
118-
}
119-
}

packages/storage/src/implementation/metadata.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ 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';
3031

3132
export function noXform_<T>(metadata: Metadata, value: T): T {
3233
return value;
@@ -206,20 +207,23 @@ export function toResourceString(
206207
return JSON.stringify(resource);
207208
}
208209

209-
export function metadataValidator(p: unknown): void {
210-
if (!type.isObject(p) || !p) {
211-
throw 'Expected Metadata object.';
212-
}
210+
export function validateMetadata(p: { [key: string]: unknown }): void {
213211
for (const key in p) {
214212
if (p.hasOwnProperty(key)) {
215213
const val = p[key];
216214
if (key === 'customMetadata') {
217215
if (!type.isObject(val)) {
218-
throw "Expected object for 'customMetadata' mapping.";
216+
throw new FirebaseStorageError(
217+
Code.INVALID_ARGUMENT,
218+
"Expected object for 'customMetadata' mapping."
219+
);
219220
}
220221
} else {
221222
if (type.isNonNullObject(val)) {
222-
throw "Mapping for '" + key + "' cannot be an object.";
223+
throw new FirebaseStorageError(
224+
Code.INVALID_ARGUMENT,
225+
"Mapping for '" + key + "' cannot be an object."
226+
);
223227
}
224228
}
225229
}

packages/storage/src/implementation/string.ts

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

30-
export function formatValidator(stringFormat: unknown): void {
31-
switch (stringFormat) {
32-
case StringFormat.RAW:
33-
case StringFormat.BASE64:
34-
case StringFormat.BASE64URL:
35-
case StringFormat.DATA_URL:
36-
return;
37-
default:
38-
throw (
39-
'Expected one of the event types: [' +
40-
StringFormat.RAW +
41-
', ' +
42-
StringFormat.BASE64 +
43-
', ' +
44-
StringFormat.BASE64URL +
45-
', ' +
46-
StringFormat.DATA_URL +
47-
'].'
48-
);
49-
}
50-
}
51-
5230
/**
5331
* @struct
5432
*/

packages/storage/src/implementation/type.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ export function isString(p: unknown): p is string {
4747
return typeof p === 'string' || p instanceof String;
4848
}
4949

50-
export function isInteger(p: unknown): p is number {
51-
return isNumber(p) && Number.isInteger(p);
52-
}
53-
54-
export function isNumber(p: unknown): p is number {
55-
return typeof p === 'number' || p instanceof Number;
56-
}
57-
5850
export function isNativeBlob(p: unknown): p is Blob {
5951
return isNativeBlobDefined() && p instanceof Blob;
6052
}

0 commit comments

Comments
 (0)