Skip to content
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

feat: support BigInt #1016

Merged
merged 3 commits into from
Apr 18, 2020
Merged

feat: support BigInt #1016

merged 3 commits into from
Apr 18, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Apr 14, 2020

This PR adds support for serializing to BigInt and for deserializing to BigInt (optional, via flag). We still need to settle on a flag name.

Fixes #872

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 14, 2020
@schmidt-sebastian schmidt-sebastian changed the base branch from master to node10 April 14, 2020 01:39
@codecov
Copy link

codecov bot commented Apr 15, 2020

Codecov Report

Merging #1016 into node10 will increase coverage by 0.00%.
The diff coverage is 99.04%.

Impacted file tree graph

@@           Coverage Diff           @@
##           node10    #1016   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files          25       25           
  Lines       16614    16620    +6     
  Branches     1258     1255    -3     
=======================================
+ Hits        16372    16379    +7     
+ Misses        239      238    -1     
  Partials        3        3           
Impacted Files Coverage Δ
dev/src/v1/firestore_client.ts 97.64% <98.96%> (ø)
dev/src/v1beta1/firestore_client.ts 97.38% <99.01%> (ø)
dev/src/v1/firestore_admin_client.ts 97.71% <99.07%> (ø)
dev/src/convert.ts 98.27% <100.00%> (-0.03%) ⬇️
dev/src/index.ts 98.28% <100.00%> (+<0.01%) ⬆️
dev/src/serializer.ts 99.02% <100.00%> (+0.26%) ⬆️
dev/src/timestamp.ts 100.00% <100.00%> (ø)
dev/src/types.ts 99.69% <100.00%> (+<0.01%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7d6888d...9f464f9. Read the comment docs.

@schmidt-sebastian schmidt-sebastian changed the title Mrschmidt/bigint feat: support BigInt Apr 17, 2020
@@ -83,15 +83,15 @@ PBJS_ARGS=( --proto_path=. \
--no-decode \
--no-verify \
--no-delimited \
--force-enum-string \
--force-number)
--force-enum-string)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to get the ProtobufJS compiler to use "string|number" in its types. It only offers "Long", "Long|number" and "number". So I chose to use "Long|number" and replace it manually with "string|number". int32 (like nanoseonds) are not affected since they can be represented as number.

@@ -177,16 +177,12 @@ export function valueFromJson(fieldValue: api.IValue): api.IValue {
return {
bytesValue: bytesFromJson(fieldValue.bytesValue!),
};
case 'integerValue':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped this since the client supports "string|number" throughout. Converting to Number results in precision loss.

Copy link

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

* Whether to use `BigInt` for integer types when deserializing Firestore
* Documents. Regardless of magnitude, all integer values will be returned as
* `BigInt` to match the precision of the Firestore backend. Floating point
* numbers continue to use JavaScript's `number` type.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe s/continue to/will for consistent future tense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted to change this to present tense for both.


constructor(firestore: Firestore) {
// Instead of storing the `firestore` object, we store just a reference to
// its `.doc()` method. This avoid a circular reference, which breaks
// JSON.stringify().
this.createReference = path => firestore.doc(path);
this.createInteger = n =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we validate the string so that Number(n) won't break on bad inputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values come from the backend and IIRC any issues with it so far (we already used this code below). Opting not do this for now.

@schmidt-sebastian schmidt-sebastian merged commit 6f9a30c into node10 Apr 18, 2020
schmidt-sebastian added a commit that referenced this pull request Jun 24, 2020
* fix!: mark v1beta1 client as deprecated (#937)

* feat!: use QueryDocumentSnapshot in FirestoreDataConverter (#965)

* deps: update to gts 2.x (#1013)

* chore!: update settings for Node 10 (#1019)

* deps: drop through2 (#1014)

* feat: support BigInt (#1016)

* fix: make update.sh work on Linux (#1043)

* fix: only use BigInt in BigInt system test (#1044)

* fix: make pbjs compile admin proto again (#1045)

* Add BulkWriter (#1055)

* docs: Add documentation for FirestoreDataConverter (#1059)

* chore: enforce return types (#1065)

* fix: add generic to Firestore.getAll() (#1066)

* chore: remove internal WriteOp (#1067)

* chore: add linter checks for it|describe.only (#1068)

* fix: handle terminate in BulkWriter (#1070)

* chore: run template copying last in synthtool (#1071)

* feat: Firestore Bundles implementation (#1078)

* feat: add support for set() with SetOptions when using FirestoreDataConverter (#1087)

* feat: Add totalDocuments and totalBytes to bundle metadata. (#1085)

* feat: Add totalDocuments and totalBytes to bundle metadata.

* fix: Better comment

* fix: Better testing.

* fix: Improve metadata testing.

* fix: incomplete expect in rate-limiter test (#1092)

* Remove BatchWrite proto, fix conformance tests

* chore: use public API types internally (#1100)

* feat: add Partition and BatchWrite protos (#1110)

* fix: remove GCF transaction fallback (#1112)

* fix: add BulkWriter integration tests, java backport changes, delete fix (#1117)

* chore: merge master (#1218)

* chore: add eslint check for console.log statements (#1229)

* fix: another attempt at fixing the flaky BulkWriter test (#1228)

* Fix comment

* Renames

* Test fix

* Fix unit tests

Co-authored-by: Brian Chen <chenbrian@google.com>
Co-authored-by: wu-hui <53845758+wu-hui@users.noreply.github.com>
@release-please release-please bot mentioned this pull request Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants