Skip to content

Commit 6dbbe61

Browse files
Merge 8a2fa65 into ef33328
2 parents ef33328 + 8a2fa65 commit 6dbbe61

File tree

12 files changed

+86
-815
lines changed

12 files changed

+86
-815
lines changed

.changeset/tiny-hounds-rest.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"firebase: major
3+
"@firebase/storage": major
4+
---
5+
6+
This releases removes all input validation. Please use our TypeScript types to validate API usage.

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: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,3 @@ export function toResourceString(
205205
}
206206
return JSON.stringify(resource);
207207
}
208-
209-
export function metadataValidator(p: unknown): void {
210-
if (!type.isObject(p) || !p) {
211-
throw 'Expected Metadata object.';
212-
}
213-
for (const key in p) {
214-
if (p.hasOwnProperty(key)) {
215-
const val = p[key];
216-
if (key === 'customMetadata') {
217-
if (!type.isObject(val)) {
218-
throw "Expected object for 'customMetadata' mapping.";
219-
}
220-
} else {
221-
if (type.isNonNullObject(val)) {
222-
throw "Mapping for '" + key + "' cannot be an object.";
223-
}
224-
}
225-
}
226-
}
227-
}

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: 23 additions & 17 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,34 +33,38 @@ 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 {
4741
return typeof p === 'string' || p instanceof String;
4842
}
4943

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-
5844
export function isNativeBlob(p: unknown): p is Blob {
5945
return isNativeBlobDefined() && p instanceof Blob;
6046
}
6147

6248
export function isNativeBlobDefined(): boolean {
6349
return typeof Blob !== 'undefined';
6450
}
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+
}

0 commit comments

Comments
 (0)