Wrap google cloud functions with a Proxy(). #3035
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Firebase wrappers such as
onRequest,onCreate, etc return callable handlers with some important additional data in properties which is being used byfirebase-cliwhile deploying the functions.So when we wrap such functions naively, these properties are not visible anymore. So I decided to circumvent it with a
new Proxy(fn, { apply: ... })trick. This proxy object will redirect all property accesses to the original function but calling behavior will be re-defined.Also added some workarounds for firebase emulator (
firebase emulators:start)fn.__emulator_functoo. See code comments.functions-framework, firebase emulator doesn't create a domain.Fixes #3023.
Also this PR removes a dependency on
@google-cloud/functions-frameworkpackage since it's used only for importing types but these types are also needed for TypeScript users and we cannot force them to install an entired functions-framework as a dependency. Instead, I moved all the types from it right in this package and also add a runtime dependency@types/express. Fixes #2997.