-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle API JSON format #36
Conversation
Codecov Report
@@ Coverage Diff @@
## master #36 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 10 11 +1
Lines 1397 1467 +70
=====================================
+ Hits 1397 1467 +70
Continue to review full report at Codecov.
|
0552716
to
555ad15
Compare
555ad15
to
bc802a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this basically looks good, though I'd like to better capture what's going on here in code comments.
At minimum, I think convert.js could maybe use a file-level comment explaining "Protobuf JS" and "API JSON" and mentioning the relation to Cloud Functions.
Also, is there any better way to describe "API JSON" ? Searching for that internally or externally doesn't yield anything useful, so I'm not sure how folks will understand this code. :-( Should it be "proto3 JSON" or something?
src/convert.js
Outdated
|
||
if (isNaN(seconds) || isNaN(nanos)) { | ||
// This error should only ever be thrown if the end-user specifies an | ||
// invalid 'lastUpdateTime'. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/convert.js
Outdated
} | ||
} | ||
/** | ||
* Converts an API JSON or Protobuf JS 'Document' into Protobuf JS. This |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/convert.js
Outdated
} | ||
/** | ||
* Converts an API JSON or Protobuf JS 'Document' into Protobuf JS. This | ||
* conversion creates a copy of underlying document. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/document.js
Outdated
seconds: seconds, | ||
nanos: nanos, | ||
}; | ||
proto.updateTime = convertTimestamp(this._lastUpdateTime); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
test/index.js
Outdated
assert.equal('1970-01-01T00:00:05.000000006Z', doc.readTime); | ||
}); | ||
|
||
it('handles API JSON', function() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -351,21 +355,24 @@ class Firestore extends commonGrpc.Service { | |||
this, | |||
ResourcePath.fromSlashSeparatedString(documentOrName) | |||
); | |||
document.readTime = DocumentSnapshot.toISOTime(readTime); | |||
} else { | |||
document.ref = new DocumentReference( | |||
this, | |||
ResourcePath.fromSlashSeparatedString(documentOrName.name) | |||
); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
e0c5eb3
to
b9ea1d9
Compare
b9ea1d9
to
570d766
Compare
I did think about adding a module level comment before, but I didn't see it anywhere else in the codebase, so I omitted it at first. I made it private and used "/*!" so I think it won't show up in the generated docs. I also changed the way the encoding works to only only convert the JSON format when required (snapshot_ now takes an encoding format). I replaced all mentions of "API JSON" to "Proto3 JSON". This does seem more common (used by https://developers.google.com/protocol-buffers/docs/proto3#json), and I hope that this is the right term - the document that describes the format doesn't mention a public name. |
d7c9a27
to
f1d6590
Compare
f1d6590
to
f9787ca
Compare
src/index.js
Outdated
@@ -336,19 +333,41 @@ class Firestore extends commonGrpc.Service { | |||
|
|||
/** | |||
* Creates a [DocumentSnapshot]{@link DocumentSnapshot} from a | |||
* `Document` proto (or from a resource name for missing documents). | |||
* `firestore.v1beta1lDocument` proto (or from a resource name for missing |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/convert.js
Outdated
|
||
if (isNaN(seconds) || isNaN(nanos)) { | ||
// This error should only ever be thrown if the end-user specifies an | ||
// invalid 'lastUpdateTime'. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think this is much clearer with the updated comments. I have a couple nits, but looks good.
Updated to pass in the argument name (it's only used in a few places). |
2895db3
to
60af922
Compare
@lukesneeringer @stephenplusplus Added you for final Approval. Thanks. |
This adds API JSON format to our internal snapshot_() API as specified by go/api-json (Sorry, this is Google Internal). This format is used by Firebase Functions, and directly exposing it means that the GCF team does not have to worry about our data format.
This was added as a conversion (rather than just adding it to decodeValue), since the logic in watch.js and order.js relies on the Protobuf JS format.
We can potentially get rid of creating the extra copy of the data, but that would mean that the input to snapshot_() gets modified.