Skip to content

Commit

Permalink
Addressing Mike's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Oct 11, 2017
1 parent f9787ca commit 60af922
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ const validate = require('./validate')();
*
* @private
* @param {*=} timestampValue - The value to convert.
* @param {string=} argumentName - The argument name to use in the error message
* if the conversion fails. If omitted, 'timestampValue' is used.
* @return {{nanos,seconds}|undefined} The value as expected by Protobuf JS or
* undefined if no input was provided.
*/
function convertTimestamp(timestampValue) {
function convertTimestamp(timestampValue, argumentName) {
let timestampProto = undefined;

if (is.string(timestampValue)) {
Expand All @@ -62,11 +64,9 @@ function convertTimestamp(timestampValue) {
}

if (isNaN(seconds) || isNaN(nanos)) {
// This error should only ever be thrown if the end-user specifies an
// invalid 'lastUpdateTime' in a precondition (hence we use
// 'lastUpdateTime' here instead of the actual argument name).
argumentName = argumentName || 'timestampValue';
throw new Error(
'Specify a valid ISO 8601 timestamp for "lastUpdateTime".'
`Specify a valid ISO 8601 timestamp for "${argumentName}".`
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,10 @@ class Precondition {
let proto = {};

if (is.defined(this._lastUpdateTime)) {
proto.updateTime = timestampFromJson(this._lastUpdateTime);
proto.updateTime = timestampFromJson(
this._lastUpdateTime,
'lastUpdateTime'
);
} else if (is.defined(this._exists)) {
proto.exists = this._exists;
}
Expand Down
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class Firestore extends commonGrpc.Service {

/**
* Creates a [DocumentSnapshot]{@link DocumentSnapshot} from a
* `firestore.v1beta1lDocument` proto (or from a resource name for missing
* `firestore.v1beta1.Document` proto (or from a resource name for missing
* documents).
*
* This API is used by Google Cloud Functions and can be called with both
Expand Down Expand Up @@ -383,14 +383,16 @@ class Firestore extends commonGrpc.Service {
? convertDocument(documentOrName.fields)
: {};
document.createTime = DocumentSnapshot.toISOTime(
convertTimestamp(documentOrName.createTime)
convertTimestamp(documentOrName.createTime, 'documentOrName.createTime')
);
document.updateTime = DocumentSnapshot.toISOTime(
convertTimestamp(documentOrName.updateTime)
convertTimestamp(documentOrName.updateTime, 'documentOrName.updateTime')
);
}

document.readTime = DocumentSnapshot.toISOTime(convertTimestamp(readTime));
document.readTime = DocumentSnapshot.toISOTime(
convertTimestamp(readTime, 'readTime')
);

return document.build();
}
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ describe('snapshot_() method', function() {
'1970-01-01T00:00:05.000000006Z',
'json'
);
}, /Specify a valid ISO 8601 timestamp for "lastUpdateTime"./);
}, /Specify a valid ISO 8601 timestamp for "documentOrName.createTime"./);
});

it('handles missing document ', function() {
Expand Down

0 comments on commit 60af922

Please sign in to comment.