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(firestore): add timestamp & fieldvalue management #677

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mamillastre
Copy link
Contributor

Pull request checklist

Please check if your PR fulfills the following requirements:

  • The changes have been tested successfully.
  • A changeset has been created (npm run changeset).
  • I have read and followed the pull request guidelines.

Close #474, #443

Linked PR: #557

Usage example:

import { FirebaseFirestore, Timestamp, serverTimestamp } from "@capacitor-firebase/firestore";

FirebaseFirestore.setDocument({
    reference: "collection/doc",
    data: {
      timestamp: Timestamp.now(),
      fieldValue: serverTimestamp()
    },
 });

@mamillastre
Copy link
Contributor Author

Hi @robingenz,

For now, this PR is a prototype of the Timestamp & FieldValue management on Web and Android.

Do you have some time to make early feedbacks on this before I continue the development?

Especially on these points:

  • You advise me here to manage the data parsing from the native layer like the Bluetooth Low Energy Plugin. But I have to implement all the plugin methods, even those that are out of scope.
    Here, I use a Proxy. Tell me if you are ok with this solution.
  • When using the plugin, the firebase dependency is mandatory for the Timestamp & FieldValue usage. But I think you prefer avoiding this.
    In this case, I see two possibilities:
    1. Copying the Timestamp code from the firebase js SDK into the plugin
    2. Set the Timestamp implementation in a separated index.js file to avoid to install the firebase dependency if the timestamp is never used

Thank you

@robingenz
Copy link
Member

@mamillastre Thanks for the update. I'm currently on vacation and won't be back for another 2 weeks. I'll have a look at it as soon as i'm back.

@mamillastre
Copy link
Contributor Author

Hi @robingenz,
Do you have some time to do a mid-term review on this feature?
This feature will have a strong impact on the plugin.
Thank you.

@robingenz
Copy link
Member

Hi @mamillastre, I'll try to take a look at your PR over the next few weeks. The problem is that this is a complex feature that will probably keep me busy for several days.

@mamillastre mamillastre force-pushed the timestamp-fieldvalue branch from cab4468 to 21be503 Compare January 6, 2025 10:10
@mamillastre
Copy link
Contributor Author

I added all the timestamp & field values methods management for the web and android platforms.

Copy link

pkg-pr-new bot commented Jan 6, 2025

Open in Stackblitz

@capacitor-firebase/analytics

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/analytics@677

@capacitor-firebase/app

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/app@677

@capacitor-firebase/app-check

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/app-check@677

@capacitor-firebase/authentication

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/authentication@677

@capacitor-firebase/crashlytics

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/crashlytics@677

@capacitor-firebase/firestore

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/firestore@677

@capacitor-firebase/functions

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/functions@677

@capacitor-firebase/messaging

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/messaging@677

@capacitor-firebase/performance

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/performance@677

@capacitor-firebase/remote-config

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/remote-config@677

@capacitor-firebase/storage

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/storage@677

commit: 5e4ca01

@mamillastre
Copy link
Contributor Author

Note on iOS: the solution to use the "toJSON()" method to serialize the timestamps and field values do not work on iOS (unlike Android).
The "toJSON()" method is not called on iOS when capacitor uses the "postMessage()" method to send data to the native platform.

Another solution must be found. For example:

  • Use the JSON.parse(JSON.stringify(data)) technique on the document data to force the serialization before calling the actual plugin method.
  • Do a deep traversal of the document data to serialize the needed data before calling the actual plugin method.

These solutions can have a negative impact on the plugin methods performances depending on the document size.

@robingenz robingenz self-assigned this Jan 7, 2025
@mamillastre mamillastre force-pushed the timestamp-fieldvalue branch from fc98ced to 5e4ca01 Compare January 9, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(firestore): Timestamp values
2 participants