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 serialization of Moment.js #879

Merged
merged 2 commits into from Jan 14, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

Fixes #753

Note that this only adds a dev dependency on the MomentJs types, but not MomentJs itself.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 14, 2020
@codecov
Copy link

codecov bot commented Jan 14, 2020

Codecov Report

Merging #879 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #879      +/-   ##
==========================================
+ Coverage    94.9%   94.91%   +<.01%     
==========================================
  Files          25       25              
  Lines       15202    15229      +27     
  Branches     1128     1134       +6     
==========================================
+ Hits        14427    14454      +27     
  Misses        767      767              
  Partials        8        8
Impacted Files Coverage Δ
dev/src/serializer.ts 95.32% <100%> (+0.33%) ⬆️

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 b7b5fc9...148d48a. Read the comment docs.

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

@@ -369,6 +381,8 @@ export function validateUserInput(
// Ok.
} else if (value instanceof Timestamp || value instanceof Date) {
// Ok.
} else if (isMomentJsType(value)) {

Choose a reason for hiding this comment

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

Just a thought -- is there value in switching the logic here to use switch/case instead of if/else blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, this doesn't make sense here since we mix "instanceof" with "typeof" among other things.


return createInstance(overrides).then(firestore => {
return firestore.doc('collectionId/documentId').set({
moonLanding: new Moment(),

Choose a reason for hiding this comment

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

indeed, what a moment that was

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the special effects!

@willbattel
Copy link

Just to be clear: this PR allows us to pass moment objects as field values with set/update operations, but does not allow querying for Timestamp values using moment objects. For the latter we still need to use toDate on the moment objects.

Is this correct?

@schmidt-sebastian
Copy link
Contributor Author

@willbattel The serialization logic is the same in all parts of the API. You should be able to use MomentJs types as query constraints.

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.

Moment.js does not work for date queries
4 participants