GoogleCloudPlatform / functions-framework-nodejs

FaaS (Function as a service) framework for writing portable Node.js functions
Apache License 2.0
1.3k stars 160 forks source link

Update Event Functions Typing #418

Closed cmbirk closed 2 years ago

cmbirk commented 2 years ago

The data field in event functions is currently set as an empty object, but I believe it should be set as a base64 encoded string: https://cloud.google.com/pubsub/docs/push

We can add a DecodedData type that accepts a generic as well so that developers can type the shape coming out of the encoded string.

I'm happy to open a PR to update the typing if it's useful.

grant commented 2 years ago

Thanks for the issue. Can you provide more detail with link to parts inside here? There is not much detail in the issue.

The types could possibly be improved, although it may be better for the type library depending on the request: https://github.com/googleapis/google-cloudevents-nodejs

grant commented 2 years ago

Hey @cmbirk, any update here?

I think you're talking about this interface:

https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/bd362430f977739d5bd4db7343f0806509c4e6f0/src/functions.ts#L53

I don't believe we can set the event object to a string for all event types.


For CloudEvents, we have the dedicated types repo (link above), with richer types.

grant commented 2 years ago

For Pub/Sub, I don't believe a string is correct either for the data field. Thus closing. Feel free to give an update if there are concerns!