Skip to content

Conversation

@grant
Copy link
Contributor

@grant grant commented Sep 10, 2020

  • Adds event type to Run Pub/Sub sample for IDE autocompletion.

@grant grant requested review from ace-n and grayside September 10, 2020 20:01
@grant grant self-assigned this Sep 10, 2020
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 10, 2020
Signed-off-by: Grant Timmerman <[email protected]>
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Sep 11, 2020
@sofisl sofisl added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 14, 2020
@sofisl sofisl removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 14, 2020

// [START run_events_pubsub_handler]
const express = require('express');
const {toMessagePublishedEvent} = require('@google/events/cloud/pubsub/v1/MessagePublishedData');
Copy link
Contributor

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.)

Copy link
Contributor Author

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);
Copy link
Contributor

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 🙂 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be non-descript.

I'm not going to write data.message.data.

(Flashbacks to data.data.data)

Copy link
Contributor Author

@grant grant left a 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');
Copy link
Contributor Author

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be non-descript.

I'm not going to write data.message.data.

(Flashbacks to data.data.data)

@grant grant closed this Sep 24, 2020
@grant grant deleted the grant_run_events_types branch March 8, 2021 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants