Skip to content

Commit 6428b23

Browse files
Merge branch 'master' into equals
2 parents 70c7d91 + 35c1af0 commit 6428b23

File tree

7 files changed

+51
-94
lines changed

7 files changed

+51
-94
lines changed

src/document.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ class DocumentTransform {
11771177
});
11781178
} else {
11791179
throw new Error(
1180-
'Server timestamps are not supported as array ' + 'values.'
1180+
'Server timestamps are not supported as array values.'
11811181
);
11821182
}
11831183
} else if (is.array(val)) {
@@ -1352,7 +1352,7 @@ function validateDocumentData(obj, options) {
13521352
* @returns {boolean} 'true' when the object is valid.
13531353
* @throws {Error} when the object is invalid.
13541354
*/
1355-
function validateFieldValue(obj, options, depth) {
1355+
function validateFieldValue(val, options, depth) {
13561356
assert(
13571357
['none', 'root', 'all'].indexOf(options.allowDeletes) !== -1,
13581358
"Expected 'none', 'root', or 'all' for 'options.allowDeletes'"
@@ -1370,17 +1370,17 @@ function validateFieldValue(obj, options, depth) {
13701370
);
13711371
}
13721372

1373-
if (is.array(obj)) {
1374-
for (let prop of obj) {
1375-
validateFieldValue(obj[prop], options, depth + 1);
1373+
if (is.array(val)) {
1374+
for (let prop of val) {
1375+
validateFieldValue(val[prop], options, depth + 1);
13761376
}
1377-
} else if (isPlainObject(obj)) {
1378-
for (let prop in obj) {
1379-
if (obj.hasOwnProperty(prop)) {
1380-
validateFieldValue(obj[prop], options, depth + 1);
1377+
} else if (isPlainObject(val)) {
1378+
for (let prop in val) {
1379+
if (val.hasOwnProperty(prop)) {
1380+
validateFieldValue(val[prop], options, depth + 1);
13811381
}
13821382
}
1383-
} else if (obj === FieldValue.DELETE_SENTINEL) {
1383+
} else if (val === FieldValue.DELETE_SENTINEL) {
13841384
if (
13851385
(options.allowDeletes === 'root' && depth > 1) ||
13861386
options.allowDeletes === 'none'
@@ -1389,20 +1389,20 @@ function validateFieldValue(obj, options, depth) {
13891389
'FieldValue.delete() must appear at the top-level and can only be used in update() or set() with {merge:true}.'
13901390
);
13911391
}
1392-
} else if (obj === FieldValue.SERVER_TIMESTAMP_SENTINEL) {
1392+
} else if (val === FieldValue.SERVER_TIMESTAMP_SENTINEL) {
13931393
if (!options.allowServerTimestamps) {
13941394
throw new Error(
13951395
'FieldValue.serverTimestamp() can only be used in update(), set() and create().'
13961396
);
13971397
}
1398-
} else if (is.instanceof(obj, DocumentReference)) {
1398+
} else if (is.instanceof(val, DocumentReference)) {
13991399
return true;
1400-
} else if (is.instanceof(obj, GeoPoint)) {
1400+
} else if (is.instanceof(val, GeoPoint)) {
14011401
return true;
1402-
} else if (is.instanceof(obj, FieldPath)) {
1402+
} else if (is.instanceof(val, FieldPath)) {
14031403
throw new Error('Cannot use "FieldPath" as a Firestore type.');
1404-
} else if (is.object(obj)) {
1405-
throw validate.customObjectError(obj);
1404+
} else if (is.object(val)) {
1405+
throw validate.customObjectError(val);
14061406
}
14071407

14081408
return true;

src/reference.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,13 +2209,13 @@ function validateComparisonOperator(str, val) {
22092209

22102210
if (typeof val === 'number' && isNaN(val) && op !== 'EQUAL') {
22112211
throw new Error(
2212-
'Invalid query. You can only perform equals ' + 'comparisons on NaN.'
2212+
'Invalid query. You can only perform equals comparisons on NaN.'
22132213
);
22142214
}
22152215

22162216
if (val === null && op !== 'EQUAL') {
22172217
throw new Error(
2218-
'Invalid query. You can only perform equals ' + 'comparisons on Null.'
2218+
'Invalid query. You can only perform equals comparisons on Null.'
22192219
);
22202220
}
22212221

src/write-batch.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ class WriteBatch {
367367
for (let i = 1; i < arguments.length; i += 2) {
368368
if (i === arguments.length - 1) {
369369
validate.isUpdatePrecondition(i, arguments[i]);
370-
validate.maxNumberOfArguments('update', arguments, i + 1);
371370
precondition = new Precondition(arguments[i]);
372371
} else {
373372
validate.isFieldPath(i, arguments[i]);

test/document.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ describe('DocumentReference interface', function() {
231231
it('has collection() method', function() {
232232
assert.throws(() => {
233233
documentRef.collection(42);
234-
}, new RegExp('Argument "collectionPath" is not a valid ResourcePath. Path must be a non-empty string.'));
234+
}, /Argument "collectionPath" is not a valid ResourcePath. Path must be a non-empty string./);
235235

236236
let collection = documentRef.collection('col');
237237
assert.equal(collection.id, 'col');
@@ -456,7 +456,7 @@ describe('serialize document', function() {
456456

457457
assert.throws(() => {
458458
firestore.doc('collectionId/documentId').update(obj);
459-
}, new RegExp('Argument "dataOrField" is not a valid Document. Input object is deeper than 20 levels or contains a cycle.'));
459+
}, /Argument "dataOrField" is not a valid Document. Input object is deeper than 20 levels or contains a cycle./);
460460
});
461461

462462
it('is able to write a document reference with cycles', function() {
@@ -852,27 +852,27 @@ describe('delete document', function() {
852852
return firestore
853853
.doc('collectionId/documentId')
854854
.delete({lastUpdateTime: 1337});
855-
}, new RegExp('"lastUpdateTime" is not a string.$'));
855+
}, /"lastUpdateTime" is not a string./);
856856
});
857857

858858
it('throws if "exists" is not a boolean', () => {
859859
assert.throws(() => {
860860
return firestore.doc('collectionId/documentId').delete({exists: 42});
861-
}, new RegExp('"exists" is not a boolean.$'));
861+
}, /"exists" is not a boolean./);
862862
});
863863

864864
it('throws if no delete conditions are provided', () => {
865865
assert.throws(() => {
866866
return firestore.doc('collectionId/documentId').delete(42);
867-
}, new RegExp('Input is not an object.'));
867+
}, /Input is not an object./);
868868
});
869869

870870
it('throws if more than one condition is provided', () => {
871871
assert.throws(() => {
872872
return firestore
873873
.doc('collectionId/documentId')
874874
.delete({exists: false, lastUpdateTime: '1985-03-18T07:20:00.123Z'});
875-
}, new RegExp('Input contains more than one condition.'));
875+
}, /Input contains more than one condition./);
876876
});
877877
});
878878

@@ -1133,13 +1133,13 @@ describe('create document', function() {
11331133
it('requires an object', function() {
11341134
assert.throws(() => {
11351135
firestore.doc('collectionId/documentId').create(null);
1136-
}, new RegExp('Argument "data" is not a valid Document. Input is not a plain JavaScript object.'));
1136+
}, /Argument "data" is not a valid Document. Input is not a plain JavaScript object./);
11371137
});
11381138

11391139
it("doesn't accept arrays", function() {
11401140
assert.throws(() => {
11411141
firestore.doc('collectionId/documentId').create([42]);
1142-
}, new RegExp('Argument "data" is not a valid Document. Input is not a plain JavaScript object.'));
1142+
}, /Argument "data" is not a valid Document. Input is not a plain JavaScript object./);
11431143
});
11441144
});
11451145

@@ -1580,7 +1580,7 @@ describe('update document', function() {
15801580
assert.throws(() => {
15811581
firestore
15821582
.doc('collectionId/documentId')
1583-
.update('foo', 'bar', {exists: true}, 'foo');
1583+
.update('foo', 'bar', {exists: true});
15841584
}, INVALID_ARGUMENTS_TO_UPDATE);
15851585

15861586
assert.throws(() => {
@@ -1593,13 +1593,13 @@ describe('update document', function() {
15931593
it('accepts an object', function() {
15941594
assert.throws(() => {
15951595
firestore.doc('collectionId/documentId').update(null);
1596-
}, new RegExp('Argument "dataOrField" is not a valid Document. Input is not a plain JavaScript object.'));
1596+
}, /Argument "dataOrField" is not a valid Document. Input is not a plain JavaScript object./);
15971597
});
15981598

15991599
it("doesn't accept arrays", function() {
16001600
assert.throws(() => {
16011601
firestore.doc('collectionId/documentId').update([42]);
1602-
}, new RegExp('Argument "dataOrField" is not a valid Document. Input is not a plain JavaScript object.'));
1602+
}, /Argument "dataOrField" is not a valid Document. Input is not a plain JavaScript object./);
16031603
});
16041604

16051605
it('with field delete', function() {

test/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,7 @@ describe('doc() method', function() {
722722
it("doesn't accept empty components", function() {
723723
assert.throws(function() {
724724
firestore.doc('coll//doc');
725-
}, new RegExp(
726-
'Argument "documentPath" is not a valid ResourcePath. ' +
727-
'Paths must not contain //.'
728-
));
725+
}, /Argument "documentPath" is not a valid ResourcePath. Paths must not contain \/\/./);
729726
});
730727

731728
it('must point to document', function() {
@@ -858,7 +855,7 @@ describe('getAll() method', function() {
858855
.catch(err => {
859856
assert.equal(
860857
err.message,
861-
'Did not receive document for' + ' "collectionId/documentId".'
858+
'Did not receive document for "collectionId/documentId".'
862859
);
863860
});
864861
});

test/query.js

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,7 @@ describe('where() interface', function() {
803803
let query = firestore.collection('collectionId');
804804
assert.throws(function() {
805805
query = query.orderBy('foo.', '=', 'foobar');
806-
}, new RegExp(
807-
'Argument "fieldPath" is not a valid FieldPath. Paths must ' +
808-
"not start or end with '.'."
809-
));
806+
}, /Argument "fieldPath" is not a valid FieldPath. Paths must not start or end with '.'./);
810807
});
811808

812809
it('verifies operator', function() {
@@ -883,10 +880,7 @@ describe('orderBy() interface', function() {
883880
let query = firestore.collection('collectionId');
884881
assert.throws(function() {
885882
query = query.orderBy('foo.');
886-
}, new RegExp(
887-
'Argument "fieldPath" is not a valid FieldPath. Paths must ' +
888-
"not start or end with '.'."
889-
));
883+
}, /Argument "fieldPath" is not a valid FieldPath. Paths must not start or end with '.'./);
890884
});
891885

892886
it('rejects call after cursor', function() {
@@ -897,40 +891,28 @@ describe('orderBy() interface', function() {
897891
.orderBy('foo')
898892
.startAt('foo')
899893
.orderBy('foo');
900-
}, new RegExp(
901-
'Cannot specify an orderBy\\(\\) constraint after calling ' +
902-
'startAt\\(\\), startAfter\\(\\), endBefore\\(\\) or endAt\\(\\)\\.'
903-
));
894+
}, /Cannot specify an orderBy\(\) constraint after calling startAt\(\), startAfter\(\), endBefore\(\) or endAt\(\)./);
904895

905896
assert.throws(function() {
906897
query = query
907898
.where('foo', '>', 'bar')
908899
.startAt(snapshot('collectionId/doc', {foo: 'bar'}))
909900
.where('foo', '>', 'bar');
910-
}, new RegExp(
911-
'Cannot specify a where\\(\\) filter after calling ' +
912-
'startAt\\(\\), startAfter\\(\\), endBefore\\(\\) or endAt\\(\\)\\.'
913-
));
901+
}, /Cannot specify a where\(\) filter after calling startAt\(\), startAfter\(\), endBefore\(\) or endAt\(\)./);
914902

915903
assert.throws(function() {
916904
query = query
917905
.orderBy('foo')
918906
.endAt('foo')
919907
.orderBy('foo');
920-
}, new RegExp(
921-
'Cannot specify an orderBy\\(\\) constraint after calling ' +
922-
'startAt\\(\\), startAfter\\(\\), endBefore\\(\\) or endAt\\(\\)\\.'
923-
));
908+
}, /Cannot specify an orderBy\(\) constraint after calling startAt\(\), startAfter\(\), endBefore\(\) or endAt\(\)./);
924909

925910
assert.throws(function() {
926911
query = query
927912
.where('foo', '>', 'bar')
928913
.endAt(snapshot('collectionId/doc', {foo: 'bar'}))
929914
.where('foo', '>', 'bar');
930-
}, new RegExp(
931-
'Cannot specify a where\\(\\) filter after calling ' +
932-
'startAt\\(\\), startAfter\\(\\), endBefore\\(\\) or endAt\\(\\)\\.'
933-
));
915+
}, /Cannot specify a where\(\) filter after calling startAt\(\), startAfter\(\), endBefore\(\) or endAt\(\)./);
934916
});
935917

936918
it('concatenates orders', function() {
@@ -1061,10 +1043,7 @@ describe('select() interface', function() {
10611043

10621044
assert.throws(function() {
10631045
query.select('.');
1064-
}, new RegExp(
1065-
'Argument at index 0 is not a valid FieldPath. Paths must ' +
1066-
"not start or end with '.'."
1067-
));
1046+
}, /Argument at index 0 is not a valid FieldPath. Paths must not start or end with '.'./);
10681047
});
10691048

10701049
it('uses latest field mask', function() {
@@ -1152,36 +1131,36 @@ describe('startAt() interface', function() {
11521131

11531132
assert.throws(() => {
11541133
query.orderBy(Firestore.FieldPath.documentId()).startAt(42);
1155-
}, new RegExp('The corresponding value for FieldPath.documentId\\(\\) must be a string or a DocumentReference\\.'));
1134+
}, /The corresponding value for FieldPath.documentId\(\) must be a string or a DocumentReference./);
11561135

11571136
assert.throws(() => {
11581137
query
11591138
.orderBy(Firestore.FieldPath.documentId())
11601139
.startAt(firestore.doc('coll/doc/other/doc'));
1161-
}, new RegExp("'coll/doc/other/doc' is not part of the query result set and cannot be used as a query boundary."));
1140+
}, /'coll\/doc\/other\/doc' is not part of the query result set and cannot be used as a query boundary./);
11621141

11631142
assert.throws(() => {
11641143
query
11651144
.orderBy(Firestore.FieldPath.documentId())
11661145
.startAt(firestore.doc('coll/doc/coll_suffix/doc'));
1167-
}, new RegExp("'coll/doc/coll_suffix/doc' is not part of the query result set and cannot be used as a query boundary."));
1146+
}, /'coll\/doc\/coll_suffix\/doc' is not part of the query result set and cannot be used as a query boundary./);
11681147

11691148
assert.throws(() => {
11701149
query
11711150
.orderBy(Firestore.FieldPath.documentId())
11721151
.startAt(firestore.doc('coll/doc'));
1173-
}, new RegExp("'coll/doc' is not part of the query result set and cannot be used as a query boundary."));
1152+
}, /'coll\/doc' is not part of the query result set and cannot be used as a query boundary./);
11741153

11751154
assert.throws(() => {
11761155
query
11771156
.orderBy(Firestore.FieldPath.documentId())
11781157
.startAt(firestore.doc('coll/doc/coll/doc/coll/doc'));
1179-
}, new RegExp("Only a direct child can be used as a query boundary. Found: 'coll/doc/coll/doc/coll/doc'."));
1158+
}, /Only a direct child can be used as a query boundary. Found: 'coll\/doc\/coll\/doc\/coll\/doc'./);
11801159

11811160
// Validate that we can't pass a reference to a collection.
11821161
assert.throws(() => {
11831162
query.orderBy(Firestore.FieldPath.documentId()).startAt('doc/coll');
1184-
}, new RegExp("Only a direct child can be used as a query boundary. Found: 'coll/doc/coll/doc/coll'."));
1163+
}, /Only a direct child can be used as a query boundary. Found: 'coll\/doc\/coll\/doc\/coll'./);
11851164
});
11861165

11871166
it('can specify document snapshot', function() {
@@ -1386,10 +1365,7 @@ describe('startAt() interface', function() {
13861365
let query = firestore.collection('collectionId');
13871366
assert.throws(function() {
13881367
query.startAt(123);
1389-
}, new RegExp(
1390-
'Too many cursor values specified\\. The specified values ' +
1391-
'must match the orderBy\\(\\) constraints of the query\\.'
1392-
));
1368+
}, /Too many cursor values specified. The specified values must match the orderBy\(\) constraints of the query./);
13931369
});
13941370

13951371
it('uses latest value', function() {
@@ -1438,10 +1414,7 @@ describe('startAfter() interface', function() {
14381414
let query = firestore.collection('collectionId');
14391415
assert.throws(function() {
14401416
query.startAfter(123);
1441-
}, new RegExp(
1442-
'Too many cursor values specified\\. The specified values ' +
1443-
'must match the orderBy\\(\\) constraints of the query\\.'
1444-
));
1417+
}, /Too many cursor values specified. The specified values must match the orderBy\(\) constraints of the query./);
14451418
});
14461419

14471420
it('uses latest value', function() {
@@ -1494,10 +1467,7 @@ describe('endAt() interface', function() {
14941467
let query = firestore.collection('collectionId');
14951468
assert.throws(function() {
14961469
query.endAt(123);
1497-
}, new RegExp(
1498-
'Too many cursor values specified\\. The specified values ' +
1499-
'must match the orderBy\\(\\) constraints of the query\\.'
1500-
));
1470+
}, /Too many cursor values specified. The specified values must match the orderBy\(\) constraints of the query./);
15011471
});
15021472

15031473
it('uses latest value', function() {
@@ -1546,10 +1516,7 @@ describe('endBefore() interface', function() {
15461516
let query = firestore.collection('collectionId');
15471517
assert.throws(function() {
15481518
query.endBefore(123);
1549-
}, new RegExp(
1550-
'Too many cursor values specified\\. The specified values ' +
1551-
'must match the orderBy\\(\\) constraints of the query\\.'
1552-
));
1519+
}, /Too many cursor values specified. The specified values must match the orderBy\(\) constraints of the query./);
15531520
});
15541521

15551522
it('uses latest value', function() {

0 commit comments

Comments
 (0)