diff --git a/functions/background/index.js b/functions/background/index.js index 2237056ba9..46fe9e82cf 100644 --- a/functions/background/index.js +++ b/functions/background/index.js @@ -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!')); @@ -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({ @@ -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!'; diff --git a/functions/datastore/index.js b/functions/datastore/index.js index 6ff99ff14d..7654ee164d 100644 --- a/functions/datastore/index.js +++ b/functions/datastore/index.js @@ -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'); @@ -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) @@ -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 diff --git a/functions/errorreporting/index.js b/functions/errorreporting/index.js index 1913fe32c5..5311d04b4d 100644 --- a/functions/errorreporting/index.js +++ b/functions/errorreporting/index.js @@ -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!'); @@ -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!'); @@ -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!'); diff --git a/functions/gcs/index.js b/functions/gcs/index.js index c2fb86c207..e2424591f8 100644 --- a/functions/gcs/index.js +++ b/functions/gcs/index.js @@ -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') { diff --git a/functions/helloworld/index.js b/functions/helloworld/index.js index 0969f2394f..4b92064127 100644 --- a/functions/helloworld/index.js +++ b/functions/helloworld/index.js @@ -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(); }; @@ -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] @@ -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] @@ -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] @@ -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'; @@ -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') { @@ -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'); }; @@ -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; }; @@ -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'); }; diff --git a/functions/http/index.js b/functions/http/index.js index b0aa62d69b..757c4edb57 100644 --- a/functions/http/index.js +++ b/functions/http/index.js @@ -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!'); @@ -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')) { @@ -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); diff --git a/functions/log/index.js b/functions/log/index.js index 7470ca23b0..5cebd11a78 100644 --- a/functions/log/index.js +++ b/functions/log/index.js @@ -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(); }; diff --git a/functions/ocr/app/index.js b/functions/ocr/app/index.js index 55653cdaa2..0c7e6ed766 100644 --- a/functions/ocr/app/index.js +++ b/functions/ocr/app/index.js @@ -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() @@ -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); @@ -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); diff --git a/functions/pubsub/index.js b/functions/pubsub/index.js index 1ea949c2c0..6957617506 100644 --- a/functions/pubsub/index.js +++ b/functions/pubsub/index.js @@ -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; @@ -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! diff --git a/functions/sendgrid/index.js b/functions/sendgrid/index.js index 12d634f10c..225fb18df4 100644 --- a/functions/sendgrid/index.js +++ b/functions/sendgrid/index.js @@ -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') { @@ -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') { @@ -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') { diff --git a/functions/sendgrid/test/index.test.js b/functions/sendgrid/test/index.test.js index fa750ca74e..39ed1ae26f 100644 --- a/functions/sendgrid/test/index.test.js +++ b/functions/sendgrid/test/index.test.js @@ -113,7 +113,7 @@ function getSample () { } function getMocks () { - var req = { + let req = { headers: {}, query: {}, body: {}, @@ -122,7 +122,7 @@ function getMocks () { } }; sinon.spy(req, 'get'); - var res = { + let res = { headers: {}, send: sinon.stub().returnsThis(), json: sinon.stub().returnsThis(), diff --git a/functions/slack/index.js b/functions/slack/index.js index a06180c4fb..534f7d31de 100644 --- a/functions/slack/index.js +++ b/functions/slack/index.js @@ -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') { diff --git a/functions/uuid/index.js b/functions/uuid/index.js index 3ac049d45d..889bf1d801 100644 --- a/functions/uuid/index.js +++ b/functions/uuid/index.js @@ -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]