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

Expose Timestamps from DocumentSnapshot #16

Open
elersong opened this issue Jul 13, 2024 · 0 comments
Open

Expose Timestamps from DocumentSnapshot #16

elersong opened this issue Jul 13, 2024 · 0 comments
Labels
enhancement New feature or request from_willyovale An issue described in original project, but never implemented planning Not yet ready for development

Comments

@elersong
Copy link
Owner

Description

Firestore's DocumentSnapshot exposes timestamps such as createTime, readTime, and updateTime. It would be beneficial to expose these timestamps in Fireorm entities, allowing users to access metadata about document operations.

Steps to Reproduce

  1. Retrieve a document using Fireorm.
  2. Attempt to access timestamps like createTime, readTime, and updateTime.

Expected Behavior

Ability to access createTime, readTime, and updateTime directly from Fireorm entities.

Actual Behavior

Currently, these timestamps are not exposed in Fireorm entities.

Acceptance Criteria

  • Implement a mechanism to expose createTime, readTime, and updateTime in Fireorm entities.
  • Ensure the implementation is clean and does not require adding arbitrary fields to entities unless needed.

Additional Context

  • May 3, 2020: Initial issue raised to expose timestamps from DocumentSnapshot.
  • May 10, 2020: Discussion on the best approach to implement this feature, considering the use of decorators or Symbols for a clean implementation.

Proposed API Changes

  1. Use of Decorators:

    • Introduce decorators to map entity fields to autogenerated or readonly fields in Firestore.
    • Example:
      @Collection()
      class MyEntity {
        id: string;
        
        @CreatedOnField()
        createTime: FirebaseFirestore.Timestamp;
        
        @ReadOnField()
        readTime: FirebaseFirestore.Timestamp;
        
        @UpdatedOnField()
        updateTime: FirebaseFirestore.Timestamp;
      }
  2. Use of Symbols:

    • Expose Symbols that developers can use to override entity fields for metadata fields.
    • Example:
      import { Symbols } from 'fireorm';
      
      @Collection()
      class MyEntity {
        id: string;
        
        [Symbols.createTime]: FirebaseFirestore.Timestamp;
        [Symbols.readTime]: FirebaseFirestore.Timestamp;
        [Symbols.updateTime]: FirebaseFirestore.Timestamp;
      }
  3. Testing and Validation:

    • Ensure thorough testing to validate that the timestamps are correctly mapped and accessible.
    • Verify that the implementation does not interfere with existing functionalities and remains backward compatible.

Original Issue

@elersong elersong added enhancement New feature or request from_willyovale An issue described in original project, but never implemented planning Not yet ready for development labels Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request from_willyovale An issue described in original project, but never implemented planning Not yet ready for development
Projects
None yet
Development

No branches or pull requests

1 participant