Conversation
|
🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use -- conventional-commit-lint bot |
ad58cc1 to
36a50cb
Compare
Revert "chore: remove compile protos from post processor (#1899)" This reverts commit 73248044166b6ba2dd102862f8cd2c4829e868db. Source-Link: googleapis/synthtool@2f0fea6 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:37f2f91dea317c75ebf4e19880aa8f10b2228b8d07859c0f384dbcf660735ba2
Revert "chore: remove compile protos from post processor (#1899)" This reverts commit 73248044166b6ba2dd102862f8cd2c4829e868db. Source-Link: https://togithub.com/googleapis/synthtool/commit/2f0fea69b6ae56dba965ea8817750793862b3b2d Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:37f2f91dea317c75ebf4e19880aa8f10b2228b8d07859c0f384dbcf660735ba2
MarkDuckworth
left a comment
There was a problem hiding this comment.
LGTM with suggestions
| } | ||
|
|
||
| public toArray(): number[] { | ||
| return this.values; |
There was a problem hiding this comment.
Consider returning a copy of the internal data so the values array cannot be modified.
There was a problem hiding this comment.
Done.
This is usually a good suggestion, I am wondering if it is as good with vectors, given the size and the likelihood of people modifying vectors.
Nevertheless, I am OK with making copies for now, and later optimize.
| export class VectorValue implements firestore.VectorValue { | ||
| private readonly values: number[]; | ||
| constructor(values: number[] | undefined) { | ||
| this.values = values || []; |
There was a problem hiding this comment.
Consider making a copy of the argument so the internal values array cannot be modified.
| 'client', | ||
| 'init', | ||
| `${JSON.stringify((client as any)._opts.servicePath)}` | ||
| ); |
There was a problem hiding this comment.
Is it intentional to leave this logger statement here?
There was a problem hiding this comment.
It looks like something you may have used for debugging.
|
|
||
| const RESERVED_MAP_KEY = '__type__'; | ||
| const RESERVED_MAP_KEY_VECTOR_VALUE = '__vector__'; | ||
| const RESERVED_VECTOR_MAP_VECTORS_KEY = 'value'; |
There was a problem hiding this comment.
nit: "RESERVED_VECTOR_MAP_VECTORS_KEY" may not need the "RESERVED_" prefix since the value is not surrounded with "__"
| return serializer.encodeVector({ | ||
| arrayValue: { | ||
| values: this.values.map(value => { | ||
| return { | ||
| doubleValue: value, | ||
| }; | ||
| }), | ||
| }, |
There was a problem hiding this comment.
nit: it's a little challenging to read this proto serialization since it is spread across this fie and the Serializer. Would it be cleaner to move the array serialization into encodeVector so it's all in one place?
There was a problem hiding this comment.
Or move the whole implementation here?
|
|
||
| const version = require('../../package.json').version; | ||
|
|
||
| setLogFunction(console.log); |
There was a problem hiding this comment.
not sure if this statement is in the PR intentionally
There was a problem hiding this comment.
Another debug line. Deleted.
| internalSettings.databaseId = process.env.FIRESTORE_NAMED_DATABASE; | ||
| } | ||
|
|
||
| settings.host = 'test-firestore.sandbox.googleapis.com'; |
There was a problem hiding this comment.
FWIW. You can also set environment variable FIRESTORE_TARGET_BACKEND=nightly to run against nightly. I set up multiple IntelliJ run configs, so easily switch back and forth.
I think this statement needs to be removed before committing.
| import api = proto.google.firestore.v1; | ||
|
|
||
| export class VectorValue implements firestore.VectorValue { | ||
| private readonly values: number[]; |
There was a problem hiding this comment.
Consider prefixing the variable with underscore to discourage use by JS developers
|
|
||
| const snap1 = await ref.get(); | ||
| expect(snap1.get('vectorEmpty')).to.deep.equal(FieldValue.vector()); | ||
| expect(snap1.get('vector1')).to.deep.equal(FieldValue.vector([1, 2, 3.99])); |
There was a problem hiding this comment.
Consider using VectorValue.isEqual instead of to.deep.equal because to.deep.equal relies on equality testing using private members.
There was a problem hiding this comment.
I want to change this in the other PR to save myself from conflict resolving, hopefully that is OK with you.
wu-hui
left a comment
There was a problem hiding this comment.
Thank for the review!
| import api = proto.google.firestore.v1; | ||
|
|
||
| export class VectorValue implements firestore.VectorValue { | ||
| private readonly values: number[]; |
| export class VectorValue implements firestore.VectorValue { | ||
| private readonly values: number[]; | ||
| constructor(values: number[] | undefined) { | ||
| this.values = values || []; |
| } | ||
|
|
||
| public toArray(): number[] { | ||
| return this.values; |
There was a problem hiding this comment.
Done.
This is usually a good suggestion, I am wondering if it is as good with vectors, given the size and the likelihood of people modifying vectors.
Nevertheless, I am OK with making copies for now, and later optimize.
| return serializer.encodeVector({ | ||
| arrayValue: { | ||
| values: this.values.map(value => { | ||
| return { | ||
| doubleValue: value, | ||
| }; | ||
| }), | ||
| }, |
| 'client', | ||
| 'init', | ||
| `${JSON.stringify((client as any)._opts.servicePath)}` | ||
| ); |
|
|
||
| const RESERVED_MAP_KEY = '__type__'; | ||
| const RESERVED_MAP_KEY_VECTOR_VALUE = '__vector__'; | ||
| const RESERVED_VECTOR_MAP_VECTORS_KEY = 'value'; |
|
|
||
| const version = require('../../package.json').version; | ||
|
|
||
| setLogFunction(console.log); |
There was a problem hiding this comment.
Another debug line. Deleted.
| internalSettings.databaseId = process.env.FIRESTORE_NAMED_DATABASE; | ||
| } | ||
|
|
||
| settings.host = 'test-firestore.sandbox.googleapis.com'; |
|
|
||
| const snap1 = await ref.get(); | ||
| expect(snap1.get('vectorEmpty')).to.deep.equal(FieldValue.vector()); | ||
| expect(snap1.get('vector1')).to.deep.equal(FieldValue.vector([1, 2, 3.99])); |
There was a problem hiding this comment.
I want to change this in the other PR to save myself from conflict resolving, hopefully that is OK with you.
No description provided.