Skip to content
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

Updates the function snippet syntax to ES6 standards. #542

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions functions/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
*
* @param {object} event The Cloud Functions event.
* @param {object} event.data The event data.
* @param {function} The callback function.
* @param {function} callback The callback function.
*/
exports.helloWorld = function helloWorld (event, callback) {
exports.helloWorld = (event, callback) => {
if (!event.data.myMessage) {
// This is an error case, "myMessage" is required
callback(new Error('No message defined!'));
Expand All @@ -44,7 +44,7 @@ exports.helloWorld = function helloWorld (event, callback) {
* @param {object} event.data The event data.
* @returns {Promise}
*/
exports.helloPromise = function helloPromise (event) {
exports.helloPromise = (event) => {
const request = require('request-promise');

return request({
Expand All @@ -61,7 +61,7 @@ exports.helloPromise = function helloPromise (event) {
* @param {object} event The Cloud Functions event.
* @param {object} event.data The event data.
*/
exports.helloSynchronous = function helloSynchronous (event) {
exports.helloSynchronous = (event) => {
// This function returns synchronously
if (event.data.something === true) {
return 'Something is true!';
Expand Down
6 changes: 3 additions & 3 deletions functions/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getKeyFromRequestData (requestData) {
* @param {object} req.body.value Value to save to Cloud Datastore, e.g. {"description":"Buy milk"}
* @param {object} res Cloud Function response context.
*/
exports.set = function set (req, res) {
exports.set = (req, res) => {
// The value contains a JSON document representing the entity we want to save
if (!req.body.value) {
throw new Error('Value not provided. Make sure you have a "value" property in your request');
Expand Down Expand Up @@ -86,7 +86,7 @@ exports.set = function set (req, res) {
* @param {string} req.body.key Key at which to retrieve the data, e.g. "sampletask1".
* @param {object} res Cloud Function response context.
*/
exports.get = function get (req, res) {
exports.get = (req, res) => {
const key = getKeyFromRequestData(req.body);

return datastore.get(key)
Expand Down Expand Up @@ -118,7 +118,7 @@ exports.get = function get (req, res) {
* @param {string} req.body.key Key at which to delete data, e.g. "sampletask1".
* @param {object} res Cloud Function response context.
*/
exports.del = function del (req, res) {
exports.del = (req, res) => {
const key = getKeyFromRequestData(req.body);

// Deletes the entity
Expand Down
8 changes: 4 additions & 4 deletions functions/errorreporting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function reportError (err, callback) {
* @param {object} req Cloud Function request context.
* @param {object} res Cloud Function response context.
*/
exports.helloSimpleError = function helloSimpleError (req, res) {
exports.helloSimpleError = (req, res) => {
try {
if (req.method !== 'GET') {
const error = new Error('Only GET requests are accepted!');
Expand Down Expand Up @@ -98,7 +98,7 @@ exports.helloSimpleError = function helloSimpleError (req, res) {
* @param {string} req.body.message Message provided in the request.
* @param {object} res Cloud Function response context.
*/
exports.helloHttpError = function helloHttpError (req, res) {
exports.helloHttpError = (req, res) => {
try {
if (req.method !== 'POST' && req.method !== 'GET') {
const error = new Error('Only POST and GET requests are accepted!');
Expand Down Expand Up @@ -126,9 +126,9 @@ exports.helloHttpError = function helloHttpError (req, res) {
* @param {object} event The Cloud Functions event.
* @param {object} event.data The event data.
* @param {string} event.data.message Message, provided by the trigger.
* @param {function} The callback function.
* @param {function} callback The callback function.
*/
exports.helloBackgroundError = function helloBackgroundError (event, callback) {
exports.helloBackgroundError = (event, callback) => {
try {
if (!event.data.message) {
throw new Error('"message" is required!');
Expand Down
4 changes: 2 additions & 2 deletions functions/gcs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ function getFileStream (file) {
* @param {object} event.data A Google Cloud Storage File object.
* @param {string} event.data.bucket Name of a Cloud Storage bucket.
* @param {string} event.data.name Name of a file in the Cloud Storage bucket.
* @param {function} The callback function.
* @param {function} callback The callback function.
*/
exports.wordCount = function (event, callback) {
exports.wordCount = (event, callback) => {
const file = event.data;

if (file.resourceState === 'not_exists') {
Expand Down
18 changes: 9 additions & 9 deletions functions/helloworld/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require('@google-cloud/debug-agent').start();
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
exports.helloWorld = function helloWorld (event, callback) {
exports.helloWorld = (event, callback) => {
console.log(`My Cloud Function: ${event.data.message}`);
callback();
};
Expand All @@ -41,7 +41,7 @@ exports.helloWorld = function helloWorld (event, callback) {
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.helloGET = function helloGET (req, res) {
exports.helloGET = (req, res) => {
res.send('Hello World!');
};
// [END functions_helloworld_get]
Expand All @@ -53,7 +53,7 @@ exports.helloGET = function helloGET (req, res) {
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.helloHttp = function helloHttp (req, res) {
exports.helloHttp = (req, res) => {
res.send(`Hello ${req.body.name || 'World'}!`);
};
// [END functions_helloworld_http]
Expand All @@ -65,7 +65,7 @@ exports.helloHttp = function helloHttp (req, res) {
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
exports.helloBackground = function helloBackground (event, callback) {
exports.helloBackground = (event, callback) => {
callback(null, `Hello ${event.data.name || 'World'}!`);
};
// [END functions_helloworld_background]
Expand All @@ -77,7 +77,7 @@ exports.helloBackground = function helloBackground (event, callback) {
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
exports.helloPubSub = function (event, callback) {
exports.helloPubSub = (event, callback) => {
const pubsubMessage = event.data;
const name = pubsubMessage.data ? Buffer.from(pubsubMessage.data, 'base64').toString() : 'World';

Expand All @@ -94,7 +94,7 @@ exports.helloPubSub = function (event, callback) {
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
exports.helloGCS = function (event, callback) {
exports.helloGCS = (event, callback) => {
const file = event.data;

if (file.resourceState === 'not_exists') {
Expand All @@ -118,7 +118,7 @@ exports.helloGCS = function (event, callback) {
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
exports.helloError = function helloError (event, callback) {
exports.helloError = (event, callback) => {
// This WILL be reported to Stackdriver errors
throw new Error('I failed you');
};
Expand All @@ -132,7 +132,7 @@ exports.helloError = function helloError (event, callback) {
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
exports.helloError2 = function helloError2 (event, callback) {
exports.helloError2 = (event, callback) => {
// This will NOT be reported to Stackdriver errors
throw 1;
};
Expand All @@ -145,7 +145,7 @@ exports.helloError2 = function helloError2 (event, callback) {
* @param {object} event The Cloud Functions event.
* @param {function} callback The callback function.
*/
exports.helloError3 = function helloError3 (event, callback) {
exports.helloError3 = (event, callback) => {
// This will NOT be reported to Stackdriver errors
callback('I failed you');
};
Expand Down
6 changes: 3 additions & 3 deletions functions/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.helloWorld = function helloWorld (req, res) {
exports.helloWorld = (req, res) => {
if (req.body.message === undefined) {
// This is an error case, as "message" is required
res.status(400).send('No message defined!');
Expand All @@ -42,7 +42,7 @@ exports.helloWorld = function helloWorld (req, res) {
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.helloContent = function helloContent (req, res) {
exports.helloContent = (req, res) => {
let name;

switch (req.get('content-type')) {
Expand Down Expand Up @@ -91,7 +91,7 @@ function handlePUT (req, res) {
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.helloHttp = function helloHttp (req, res) {
exports.helloHttp = (req, res) => {
switch (req.method) {
case 'GET':
handleGET(req, res);
Expand Down
2 changes: 1 addition & 1 deletion functions/log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'use strict';

// [START functions_log_helloworld]
exports.helloWorld = function helloWorld (event, callback) {
exports.helloWorld = (event, callback) => {
console.log('I am a log entry!');
callback();
};
Expand Down
6 changes: 3 additions & 3 deletions functions/ocr/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function renameImageForSave (filename, lang) {
* @param {object} event The Cloud Functions event.
* @param {object} event.data A Google Cloud Storage File object.
*/
exports.processImage = function processImage (event) {
exports.processImage = (event) => {
let file = event.data;

return Promise.resolve()
Expand Down Expand Up @@ -144,7 +144,7 @@ exports.processImage = function processImage (event) {
* @param {string} event.data.data The "data" property of the Cloud Pub/Sub
* Message. This property will be a base64-encoded string that you must decode.
*/
exports.translateText = function translateText (event) {
exports.translateText = (event) => {
const pubsubMessage = event.data;
const jsonStr = Buffer.from(pubsubMessage.data, 'base64').toString();
const payload = JSON.parse(jsonStr);
Expand Down Expand Up @@ -194,7 +194,7 @@ exports.translateText = function translateText (event) {
* @param {string} event.data.data The "data" property of the Cloud Pub/Sub
* Message. This property will be a base64-encoded string that you must decode.
*/
exports.saveResult = function saveResult (event) {
exports.saveResult = (event) => {
const pubsubMessage = event.data;
const jsonStr = Buffer.from(pubsubMessage.data, 'base64').toString();
const payload = JSON.parse(jsonStr);
Expand Down
6 changes: 3 additions & 3 deletions functions/pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Buffer = require('safe-buffer').Buffer;
* @param {string} req.body.message Message to publish.
* @param {object} res Cloud Function response context.
*/
exports.publish = function publish (req, res) {
exports.publish = (req, res) => {
if (!req.body.topic) {
res.status(500).send(new Error('Topic not provided. Make sure you have a "topic" property in your request'));
return;
Expand Down Expand Up @@ -77,9 +77,9 @@ exports.publish = function publish (req, res) {
* @param {object} event The Cloud Functions event.
* @param {object} event.data The Cloud Pub/Sub Message object.
* @param {string} event.data.data The "data" property of the Cloud Pub/Sub Message.
* @param {function} The callback function.
* @param {function} callback The callback function.
*/
exports.subscribe = function subscribe (event, callback) {
exports.subscribe = (event, callback) => {
const pubsubMessage = event.data;

// We're just going to log the message to prove that it worked!
Expand Down
6 changes: 3 additions & 3 deletions functions/sendgrid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function getPayload (requestBody) {
* @param {string} req.body.body Body of the email subject line.
* @param {object} res Cloud Function response context.
*/
exports.sendgridEmail = function sendgridEmail (req, res) {
exports.sendgridEmail = (req, res) => {
return Promise.resolve()
.then(() => {
if (req.method !== 'POST') {
Expand Down Expand Up @@ -224,7 +224,7 @@ function fixNames (obj) {
* @param {object} req Cloud Function request context.
* @param {object} res Cloud Function response context.
*/
exports.sendgridWebhook = function sendgridWebhook (req, res) {
exports.sendgridWebhook = (req, res) => {
return Promise.resolve()
.then(() => {
if (req.method !== 'POST') {
Expand Down Expand Up @@ -291,7 +291,7 @@ function getTable () {
* @param {string} [event.data.timeDeleted] Time the file was deleted if this is a deletion event.
* @see https://cloud.google.com/storage/docs/json_api/v1/objects#resource
*/
exports.sendgridLoad = function sendgridLoad (event) {
exports.sendgridLoad = (event) => {
const file = event.data;

if (file.resourceState === 'not_exists') {
Expand Down
4 changes: 2 additions & 2 deletions functions/sendgrid/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function getSample () {
}

function getMocks () {
var req = {
let req = {
headers: {},
query: {},
body: {},
Expand All @@ -122,7 +122,7 @@ function getMocks () {
}
};
sinon.spy(req, 'get');
var res = {
let res = {
headers: {},
send: sinon.stub().returnsThis(),
json: sinon.stub().returnsThis(),
Expand Down
2 changes: 1 addition & 1 deletion functions/slack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function makeSearchRequest (query) {
* @param {string} req.body.text The user's search query.
* @param {object} res Cloud Function response object.
*/
exports.kgSearch = function kgSearch (req, res) {
exports.kgSearch = (req, res) => {
return Promise.resolve()
.then(() => {
if (req.method !== 'POST') {
Expand Down
2 changes: 1 addition & 1 deletion functions/uuid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
const uuid = require('uuid');

// Return a newly generated UUID in the HTTP response.
exports.getUuid = function (req, res) {
exports.getUuid = (req, res) => {
res.send(uuid.v4());
};
// [END functions_uuid]