googleapis / nodejs-storage

Node.js client for Google Cloud Storage: unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
https://cloud.google.com/storage/
Apache License 2.0
892 stars 367 forks source link

refactor(deps): Remove `@google-cloud/promisify` dependency in favor of native implementation #1967

Open danielbankhead opened 2 years ago

danielbankhead commented 2 years ago

Currently we utilize @google-cloud/promisify in numerous files to create functions and methods that handle both callback and Promises APIs. The problem with this approach is that it's difficult to determine when something is promisified on the type-level and it makes debugging/understanding the codebase a bit more cumbersome (it can come off as 'magic' for newcomers).

Source: https://github.com/googleapis/nodejs-storage/blob/a9c4c182827e221ad7324d0664e2a3c2fa72c41c/src/file.ts#L4121-L4130

Example (difficult to understand how a Promise is returned):

https://github.com/googleapis/nodejs-storage/blob/a9c4c182827e221ad7324d0664e2a3c2fa72c41c/src/file.ts#L1532-L1676

Going forward, we should handle the logic directly in the methods - in a seamless way when possible. Idea: Perhaps have an internal/private Promise-only (async/await) version of methods, and have the public methods internally handling all difference between callback and Promise (e.g. most logic would be in the internalized-async/await function).

danielbankhead commented 1 year ago

This utility may help: https://github.com/googleapis/nodejs-storage/blob/0ddef7e81d86c0f12c0cfeb49dd7b8e8ba8f1822/src/util.ts#L18-L29