nodejs-storage
nodejs-storage copied to clipboard
refactor(deps): Remove `@google-cloud/promisify` dependency in favor of native implementation
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).
This utility may help: https://github.com/googleapis/nodejs-storage/blob/0ddef7e81d86c0f12c0cfeb49dd7b8e8ba8f1822/src/util.ts#L18-L29