Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Add typing for File.metadata #1817

Closed
Closed

Description

@northern-mindset

Environment details

  • OS: Windows
  • Node.js version: 12.20.0
  • npm version: 6.14.8
  • @google-cloud/storage version: 5.18.2

Steps to reproduce

  1. Create instance of the File class.
  2. Access its metadata property in TypeScript.

The issue is that its type is effectively … any, whereas the reference and example demonstrate the structure of the metadata.

Why not to add this structure to the typing?

Activity

  1. added
    priority: p2
    type: bug
    on Mar 16, 2022
  2. added
    api: storage
    on Mar 16, 2022
  3. added
    type: feature request
    and removed
    type: bug
    on Mar 16, 2022
  4. added
    type: question
    and removed
    priority: p2
    type: feature request
    on Mar 16, 2022
  5. shaffeeullah commented on Mar 16, 2022

    @shaffeeullah
    Contributor

    Hi @anantakrishna ,

    This is done on purpose. We don't believe it is good practice to validate the data returned by the server. The way this is currently implemented, the data returned by the server gets propagated to you without being processed in any way. This is safer from bugs on our end because if Cloud Storage changes/adds metadata fields, consumers of this library will get those changes without the current version of the library breaking and/or having to upgrade versions.

  6. self-assigned this
    on Mar 16, 2022
  7. northern-mindset commented on Mar 17, 2022

    @northern-mindset
    Author

    Thank you @shaffeeullah for explanation. I partly agree with this logic, however not fully. Let me explain further.

    • Now metadata contains such properties as md5Hash, cacheControl and other standard metadata keys.
    • Some of them are listed in the metadata docs, and more thoroughly they are listed in the JSON API reference.
    • The fact that they are listed in the reference seems to mean that the Google Cloud Storage product is committed to their naming and presence.
    • This in turn means that the consumer software can rely on them in the source code, which happens de-facto, I believe.
    • If and when Storage changes the metadata fields, be it removing or renaming, it will break the consumer software regardless of whether the nodejs-storage library has typing support for these metadata keys or not.
    • Adding new metadata keys is not a problem, the typing can allow unmentioned properties in the interface.
    • Typing on itself does not do any transformation of the data, therefore the fact that “data returned by the server gets propagated to you without being processed in any way” is not a concern here.
    • The main purpose of adding well-known metadata keys as properties of the Metadata type is to facilitate discoverability and type checking. Currently, when one tries to dig into the File.metadata propery, they face ambiguous any and have to research somewhere else on what are the exact metadata keys there.

    I hope now the background of my inquiry is clearer.

  8. shaffeeullah commented on Mar 18, 2022

    @shaffeeullah
    Contributor

    Hi @anantakrishna while I agree that these are strong advantages of including typing for Metadata, I still believe that the disadvantages are more impactful.

    • If we add typing, users must upgrade the library in order to get new metadata fields instead of getting them automatically
    • We don't have a great way of supporting public preview in this library. When GCS metadata features are in public preview, adding those fields to this library potentially leads us to tech debt later (we can't remove fields in this library because that would be a breaking change.
    • This feature request in itself is a breaking change.
  9. shaffeeullah commented on Apr 20, 2022

    @shaffeeullah
    Contributor

    Hi @fmmoret ,

    This is a fair suggestion. We will consider implementing this. It isn't a breaking change and will allow users to access new GCS metadata fields without upgrading the library.

  10. added
    type: feature request
    and removed
    type: question
    on Apr 20, 2022
  11. added
    next major: breaking change
    on Aug 12, 2022
  12. added
    priority: p3
    on Oct 27, 2022
  13. iiian commented on Jan 9, 2023

    @iiian

    For my part, being able to access the generation number of the file has value, and since generation number is housed under metadata, it would be nice to have a type contract, or to have generation number live elsewhere even.

  14. danielbankhead commented on Jul 25, 2023

    @danielbankhead
    Contributor

    Fixed via #2234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: storagenext major: breaking changepriority: p3type: feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions