Skip to content

Commit 1038763

Browse files
Remove JS Input Validation
1 parent 00c963b commit 1038763

File tree

9 files changed

+41
-882
lines changed

9 files changed

+41
-882
lines changed

packages/firestore/lite/src/api/field_value.ts

-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { validateAtLeastNumberOfArgs } from '../../../src/util/input_validation';
1918
import {
2019
ArrayRemoveFieldValueImpl,
2120
ArrayUnionFieldValueImpl,
@@ -69,7 +68,6 @@ export function serverTimestamp(): FieldValue {
6968
* `updateDoc()`.
7069
*/
7170
export function arrayUnion(...elements: unknown[]): FieldValue {
72-
validateAtLeastNumberOfArgs('arrayUnion()', arguments, 1);
7371
// NOTE: We don't actually parse the data until it's used in set() or
7472
// update() since we'd need the Firestore instance to do this.
7573
return new ArrayUnionFieldValueImpl('arrayUnion', elements);
@@ -87,7 +85,6 @@ export function arrayUnion(...elements: unknown[]): FieldValue {
8785
* `updateDoc()`
8886
*/
8987
export function arrayRemove(...elements: unknown[]): FieldValue {
90-
validateAtLeastNumberOfArgs('arrayRemove()', arguments, 1);
9188
// NOTE: We don't actually parse the data until it's used in set() or
9289
// update() since we'd need the Firestore instance to do this.
9390
return new ArrayRemoveFieldValueImpl('arrayRemove', elements);

packages/firestore/lite/src/api/reference.ts

+4-22
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import { FieldPath } from './field_path';
7373
import {
7474
validateCollectionPath,
7575
validateDocumentPath,
76-
validateExactNumberOfArgs,
76+
validateNonEmptyString,
7777
validatePositiveNumber
7878
} from '../../../src/util/input_validation';
7979
import { newSerializer } from '../../../src/platform/serializer';
@@ -335,8 +335,6 @@ export function where(
335335
opStr: WhereFilterOp,
336336
value: unknown
337337
): QueryConstraint {
338-
// TODO(firestorelite): Consider validating the enum strings (note that
339-
// TypeScript does not support passing invalid values).
340338
const op = opStr as Operator;
341339
const field = fieldPathFromArgument('where', fieldPath);
342340
return new QueryFilterConstraint(field, op, value);
@@ -381,8 +379,6 @@ export function orderBy(
381379
fieldPath: string | FieldPath,
382380
directionStr: OrderByDirection = 'asc'
383381
): QueryConstraint {
384-
// TODO(firestorelite): Consider validating the enum strings (note that
385-
// TypeScript does not support passing invalid values).
386382
const direction = directionStr as Direction;
387383
const path = fieldPathFromArgument('orderBy', fieldPath);
388384
return new QueryOrderByConstraint(path, direction);
@@ -597,7 +593,6 @@ function newQueryBoundFromDocOrFields<T>(
597593
before: boolean
598594
): Bound {
599595
if (docOrFields[0] instanceof DocumentSnapshot) {
600-
validateExactNumberOfArgs(methodName, docOrFields, 1);
601596
return newQueryBoundFromDocument(
602597
query._query,
603598
query.firestore._databaseId,
@@ -738,7 +733,7 @@ export function collection(
738733
path: string,
739734
...pathSegments: string[]
740735
): CollectionReference<DocumentData> {
741-
validateNonEmptyArgument('collection', 'path', path);
736+
validateNonEmptyString('collection', 'path', path);
742737
if (parent instanceof FirebaseFirestore) {
743738
const absolutePath = ResourcePath.fromString(path, ...pathSegments);
744739
validateCollectionPath(absolutePath);
@@ -785,7 +780,7 @@ export function collectionGroup(
785780
firestore: FirebaseFirestore,
786781
collectionId: string
787782
): Query<DocumentData> {
788-
validateNonEmptyArgument('collectionGroup', 'collection id', collectionId);
783+
validateNonEmptyString('collectionGroup', 'collection id', collectionId);
789784
if (collectionId.indexOf('/') >= 0) {
790785
throw new FirestoreError(
791786
Code.INVALID_ARGUMENT,
@@ -868,7 +863,7 @@ export function doc<T>(
868863
if (arguments.length === 1) {
869864
path = AutoId.newId();
870865
}
871-
validateNonEmptyArgument('doc', 'path', path);
866+
validateNonEmptyString('doc', 'path', path);
872867

873868
if (parent instanceof FirebaseFirestore) {
874869
const absolutePath = ResourcePath.fromString(path, ...pathSegments);
@@ -1234,16 +1229,3 @@ export function newUserDataReader(
12341229
serializer
12351230
);
12361231
}
1237-
1238-
function validateNonEmptyArgument(
1239-
functionName: string,
1240-
argumentName: string,
1241-
argument?: string
1242-
): asserts argument is string {
1243-
if (!argument) {
1244-
throw new FirestoreError(
1245-
Code.INVALID_ARGUMENT,
1246-
`Function ${functionName}() cannot be called with an empty ${argumentName}.`
1247-
);
1248-
}
1249-
}

packages/firestore/src/api/blob.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717

1818
import { isBase64Available } from '../platform/base64';
1919
import { Code, FirestoreError } from '../util/error';
20-
import {
21-
invalidClassError,
22-
validateArgType,
23-
validateExactNumberOfArgs
24-
} from '../util/input_validation';
20+
import { invalidClassError } from '../util/input_validation';
2521
import { ByteString } from '../util/byte_string';
2622
import { Bytes } from '../../lite/src/api/bytes';
2723

@@ -57,8 +53,6 @@ function assertBase64Available(): void {
5753
*/
5854
export class Blob extends Bytes {
5955
static fromBase64String(base64: string): Blob {
60-
validateExactNumberOfArgs('Blob.fromBase64String', arguments, 1);
61-
validateArgType('Blob.fromBase64String', 'string', 1, base64);
6256
assertBase64Available();
6357
try {
6458
return new Blob(ByteString.fromBase64String(base64));
@@ -71,7 +65,6 @@ export class Blob extends Bytes {
7165
}
7266

7367
static fromUint8Array(array: Uint8Array): Blob {
74-
validateExactNumberOfArgs('Blob.fromUint8Array', arguments, 1);
7568
assertUint8ArrayAvailable();
7669
if (!(array instanceof Uint8Array)) {
7770
throw invalidClassError('Blob.fromUint8Array', 'Uint8Array', 1, array);
@@ -80,13 +73,11 @@ export class Blob extends Bytes {
8073
}
8174

8275
toBase64(): string {
83-
validateExactNumberOfArgs('Blob.toBase64', arguments, 0);
8476
assertBase64Available();
8577
return super.toBase64();
8678
}
8779

8880
toUint8Array(): Uint8Array {
89-
validateExactNumberOfArgs('Blob.toUint8Array', arguments, 0);
9081
assertUint8ArrayAvailable();
9182
return super.toUint8Array();
9283
}

0 commit comments

Comments
 (0)