Skip to content

Commit 6f2b338

Browse files
author
Brian Chen
committed
taking a stab at fixing this
1 parent 0119d66 commit 6f2b338

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

packages/firestore/exp/src/api/transaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import { Transaction as InternalTransaction } from '../../../src/core/transactio
2929
import { validateReference } from '../../../lite/src/api/write_batch';
3030
import { getDatastore } from '../../../lite/src/api/components';
3131

32-
export class Transaction extends LiteTransaction
32+
export class Transaction
33+
extends LiteTransaction
3334
implements firestore.Transaction {
3435
// This class implements the same logic as the Transaction API in the Lite SDK
3536
// but is subclassed in order to return its own DocumentSnapshot types.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import { ParseContext } from '../../../src/api/user_data_reader';
3030
import { FieldTransform } from '../../../src/model/mutation';
3131

3232
/** The public FieldValue class of the lite API. */
33-
export abstract class FieldValue extends SerializableFieldValue
33+
export abstract class FieldValue
34+
extends SerializableFieldValue
3435
implements firestore.FieldValue {}
3536

3637
/**

packages/firestore/src/api/database.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,17 +1101,23 @@ export class DocumentReference<T = DocumentData>
11011101

11021102
set(value: Partial<T>, options: SetOptions): Promise<void>;
11031103
set(value: T): Promise<void>;
1104-
set(value: T | Partial<T>, options?: SetOptions): Promise<void> {
1105-
validateBetweenNumberOfArgs('DocumentReference.set', arguments, 1, 2);
1106-
options = validateSetOptions('DocumentReference.set', options);
1104+
set(value: T, options?: SetOptions, parentFnName?: string): Promise<void>;
1105+
set(
1106+
value: T | Partial<T>,
1107+
options?: SetOptions,
1108+
parentFnName?: string
1109+
): Promise<void> {
1110+
const methodName = parentFnName ? parentFnName : 'DocumentReference.set';
1111+
validateBetweenNumberOfArgs(methodName, arguments, 1, 3);
1112+
options = validateSetOptions(methodName, options);
11071113
const convertedValue = applyFirestoreDataConverter(
11081114
this._converter,
11091115
value,
11101116
options
11111117
);
11121118
const parsed = parseSetData(
11131119
this.firestore._dataReader,
1114-
'DocumentReference.set',
1120+
methodName,
11151121
this._key,
11161122
convertedValue,
11171123
this._converter !== null,
@@ -2375,12 +2381,10 @@ export class CollectionReference<T = DocumentData>
23752381

23762382
add(value: T): Promise<PublicDocumentReference<T>> {
23772383
validateExactNumberOfArgs('CollectionReference.add', arguments, 1);
2378-
const convertedValue = this._converter
2379-
? this._converter.toFirestore(value)
2380-
: value;
2381-
validateArgType('CollectionReference.add', 'object', 1, convertedValue);
23822384
const docRef = this.doc();
2383-
return docRef.set(value).then(() => docRef);
2385+
return ((docRef as unknown) as DocumentReference)
2386+
.set(value, undefined, 'CollectionReference.add')
2387+
.then(() => docRef);
23842388
}
23852389

23862390
withConverter<U>(

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,18 @@ apiDescribe('Validation:', (persistence: boolean) => {
589589
});
590590
});
591591

592+
validationIt(
593+
persistence,
594+
'validates CollectionReference.add with correct function name',
595+
db => {
596+
const coll = db.collection('foo');
597+
598+
expect(() => coll.add(new TestClass('foo'))).to.throw(
599+
'Function CollectionReference.add() called with invalid data.'
600+
);
601+
}
602+
);
603+
592604
validationIt(persistence, 'must not contain undefined.', db => {
593605
// Note: This test uses the default setting for `ignoreUndefinedProperties`.
594606
return expectWriteToFail(

0 commit comments

Comments
 (0)