-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add event type conversion to run pubsub event sample #1971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
grant
commented
Sep 10, 2020
- Adds event type to Run Pub/Sub sample for IDE autocompletion.
Signed-off-by: Grant Timmerman <[email protected]>
Signed-off-by: Grant Timmerman <[email protected]>
Signed-off-by: Grant Timmerman <[email protected]>
|
|
||
| // [START run_events_pubsub_handler] | ||
| const express = require('express'); | ||
| const {toMessagePublishedEvent} = require('@google/events/cloud/pubsub/v1/MessagePublishedData'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - I don't imagine someone can do something like this?
const {toMessagePublishedEvent} = require('@google/events/cloud/pubsub/v1').MessagePublishedData;
(I ask because this format makes reverse engineering/"exploring" the "type definition universe" a bit easier, via Node's built-in debugging tools.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, we can do that. Going to hold off for right now though.
| const name = pubSubMessage.data | ||
| ? Buffer.from(pubSubMessage.data, 'base64').toString().trim() | ||
| // Cast to MessagePublishedEvent for IDE autocompletion | ||
| const pubSubMessage = toMessagePublishedEvent(req.body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: would message be too non-descript here? (It's shorter 🙂 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reviews! Going to add the types later.
There are going to be a couple future changes to the Node types repo, and I'll look back to this PR later.
|
|
||
| // [START run_events_pubsub_handler] | ||
| const express = require('express'); | ||
| const {toMessagePublishedEvent} = require('@google/events/cloud/pubsub/v1/MessagePublishedData'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, we can do that. Going to hold off for right now though.
| const name = pubSubMessage.data | ||
| ? Buffer.from(pubSubMessage.data, 'base64').toString().trim() | ||
| // Cast to MessagePublishedEvent for IDE autocompletion | ||
| const pubSubMessage = toMessagePublishedEvent(req.body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.