feat: add toJson method to Timestamp#290
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a toJson method to the Timestamp class to make it encodable, along with corresponding unit tests and a changelog update. The reviewer recommends implementing a symmetric fromJson factory constructor, changing the return type of toJson to the idiomatic Map<String, dynamic>, and adding unit tests to verify the deserialization logic.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #290 +/- ##
=======================================
Coverage ? 75.19%
=======================================
Files ? 105
Lines ? 6873
Branches ? 0
=======================================
Hits ? 5168
Misses ? 1705
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
I think this should be in the firebase_functions package itself, specifically CallableResponse in callable.dart https://github.com/firebase/firebase-functions-dart/blob/main/lib/src/https/callable.dart#L419-L457.
Also, Timestamp.toJson() should not be used internally since the bundle serialization format requires a different set of map keys (seconds/nanos).
|
hi @demolaf, the Timestamp in node.js is natively encodable without depending on import { Timestamp } from "firebase-admin/firestore";
const now = Timestamp.now();
console.log(JSON.stringify(now)); // {"_seconds":1782405004,"_nanoseconds":354000000}Having a native Also, the
|
|
@Lyokone @lahirumaramba can I get your thoughts on this? my main concern here is firebase functions node never had this concern because it doesn't declare a @OutdatedGuy encode is not only for streaming responses, see node reference https://github.com/firebase/firebase-functions/blob/master/src/common/providers/https.ts#L919-L927 it's job here is to convert types into json compatible values/throws for incompatible json values and that's actually a bug that it is not being called in the idea here is to let firebase functions dart handle functions specific work instead of firebase admin since it can't defend against node's default behavior. |
Related Issues
fixes #289
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]).I have updated the
CHANGELOG.mdof the relevant packages.Changelog files must be edited under the form:
If this contains new features or behavior changes,
I have updated the documentation to match those changes.