Skip to content

Commit 2850a2c

Browse files
author
Brian Chen
committed
incorporating first round of changes
1 parent 55d5aa3 commit 2850a2c

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

packages/firestore/src/api/database.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import { AsyncQueue } from '../util/async_queue';
5959
import { Code, FirestoreError } from '../util/error';
6060
import {
6161
invalidClassError,
62-
validateArgEnum,
6362
validateArgType,
6463
validateAtLeastNumberOfArgs,
6564
validateBetweenNumberOfArgs,
@@ -71,6 +70,7 @@ import {
7170
validateOptionalArgType,
7271
validateOptionalArrayElements,
7372
validateOptionNames,
73+
validateStringEnum,
7474
valueDescription
7575
} from '../util/input_validation';
7676
import * as log from '../util/log';
@@ -1353,17 +1353,10 @@ export class Query implements firestore.Query {
13531353
value: unknown
13541354
): firestore.Query {
13551355
validateExactNumberOfArgs('Query.where', arguments, 3);
1356-
validateArgType('Query.where', 'non-empty string', 2, opStr);
13571356
validateDefined('Query.where', 3, value);
13581357
// Enumerated from the WhereFilterOp type in index.d.ts.
13591358
const whereFilterOpEnums = ['<', '<=', '==', '>=', '>', 'array-contains'];
1360-
validateArgEnum(
1361-
'Query.where',
1362-
whereFilterOpEnums,
1363-
'WhereFilterOp',
1364-
2,
1365-
opStr
1366-
);
1359+
validateStringEnum('Query.where', whereFilterOpEnums, 2, opStr);
13671360
let fieldValue;
13681361
const fieldPath = fieldPathFromArgument('Query.where', field);
13691362
const relationOp = RelationOp.fromString(opStr);

packages/firestore/src/util/input_validation.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ export function validateArgType(
151151
position: number,
152152
argument: unknown
153153
): void {
154-
// console.log('validating: ', argument, 'as', type);
155154
validateType(functionName, type, `${ordinal(position)} argument`, argument);
156155
}
157156

@@ -293,26 +292,24 @@ export function validateNamedOptionalPropertyEquals<T>(
293292
}
294293

295294
/**
296-
* Validates that the provided argument is part of the
295+
* Validates that the provided argument is a valid enum.
297296
*
298297
* @param functionName Function making the validation call.
299298
* @param enums Array containing all possible values for the enum.
300-
* @param enumName Custom type name.
301299
* @param position Position of the argument in `functionName`.
302300
* @param argument Arugment to validate.
303301
*/
304-
export function validateArgEnum<T>(
302+
export function validateStringEnum<T>(
305303
functionName: string,
306304
enums: string[],
307-
enumName: string,
308305
position: number,
309-
argument: string
306+
argument: unknown
310307
): void {
311308
if (!enums.some(element => element === argument)) {
312309
throw new FirestoreError(
313310
Code.INVALID_ARGUMENT,
314-
`Function ${functionName}() requires its ${ordinal(position)} ` +
315-
`argument to be of type ${enumName}, but it was: ${argument}`
311+
`Invalid value ${argument} provided to function ${functionName}() for its` +
312+
` ${ordinal(position)} argument. Acceptable values: ${enums.join(', ')}`
316313
);
317314
}
318315
}

packages/firestore/test/integration/api/validation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ apiDescribe('Validation:', persistence => {
803803
validationIt(persistence, 'enum', db => {
804804
const collection = db.collection('test') as any;
805805
expect(() => collection.where('a', 'foo', 'b')).to.throw(
806-
'Function Query.where() requires its second argument to be of type WhereFilterOp,' +
807-
' but it was: foo'
806+
'Invalid value foo provided to function Query.where() for its second argument. ' +
807+
'Acceptable values: <, <=, ==, >=, >, array-contains'
808808
);
809809
});
810810

0 commit comments

Comments
 (0)