Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .github/config/nodejs-dev.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"datacatalog/quickstart",
"datacatalog/snippets",
"datalabeling",
"datastore/functions",
"dialogflow",
"discoveryengine",
"document-warehouse",
Expand Down
1 change: 0 additions & 1 deletion .github/config/nodejs.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
"cloud-sql/sqlserver/tedious", // (untested) TypeError: The "config.server" property is required and must be of type string.
"compute", // GoogleError: The resource 'projects/long-door-651/zones/us-central1-a/disks/disk-from-pool-name' was not found
"dataproc", // GoogleError: Error submitting create cluster request: Multiple validation errors
"datastore/functions", // [ERR_REQUIRE_ESM]: require() of ES Module
"dialogflow-cx", // NOT_FOUND: com.google.apps.framework.request.NotFoundException: Agent 'undefined' does not exist
"dlp", // [ERR_REQUIRE_ESM]: require() of ES Module
"document-ai", // [ERR_REQUIRE_ESM]: require() of ES Module
Expand Down
14 changes: 7 additions & 7 deletions datastore/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const {Datastore} = require('@google-cloud/datastore');
import {Datastore} from '@google-cloud/datastore';
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider using import for all dependencies to maintain consistency with ES module syntax. Since the package.json now specifies type: module, it's best to avoid require statements.

Suggested change
import {Datastore} from '@google-cloud/datastore';
import { Datastore } from '@google-cloud/datastore';


// Instantiates a client
const datastore = new Datastore();
Expand Down Expand Up @@ -58,7 +58,7 @@ const 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 = async (req, res) => {
export async function set(req, res) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a JSDoc comment for the set function to describe its purpose, parameters, and return value. This will improve the code's documentation and make it easier to understand.

Suggested change
export async function set(req, res) {
/**
* Creates and/or updates a record.
*
* @param {object} req Cloud Function request context.
* @param {object} res Cloud Function response context.
* @returns {Promise<void>}
*/
export async function set(req, res) {

// The value contains a JSON document representing the entity we want to save
if (!req.body.value) {
const err = makeErrorObj('Value');
Expand All @@ -80,7 +80,7 @@ exports.set = async (req, res) => {
console.error(new Error(err.message)); // Add to Stackdriver Error Reporting
res.status(500).send(err.message);
}
};
}

/**
* Retrieves a record.
Expand All @@ -94,7 +94,7 @@ exports.set = async (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 = async (req, res) => {
export async function get(req, res) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a JSDoc comment for the get function to describe its purpose, parameters, and return value. This will improve the code's documentation and make it easier to understand.

/**
 * Retrieves a record.
 *
 * @param {object} req Cloud Function request context.
 * @param {object} res Cloud Function response context.
 * @returns {Promise<void>}
 */
export async function get(req, res) {

try {
const key = await getKeyFromRequestData(req.body);
const [entity] = await datastore.get(key);
Expand All @@ -110,7 +110,7 @@ exports.get = async (req, res) => {
console.error(new Error(err.message)); // Add to Stackdriver Error Reporting
res.status(500).send(err.message);
}
};
}

/**
* Deletes a record.
Expand All @@ -124,7 +124,7 @@ exports.get = async (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 = async (req, res) => {
export async function del(req, res) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a JSDoc comment for the del function to describe its purpose, parameters, and return value. This will improve the code's documentation and make it easier to understand.

/**
 * Deletes a record.
 *
 * @param {object} req Cloud Function request context.
 * @param {object} res Cloud Function response context.
 * @returns {Promise<void>}
 */
export async function del(req, res) {

// Deletes the entity
// The delete operation will not fail for a non-existent entity, it just
// doesn't delete anything
Expand All @@ -136,4 +136,4 @@ exports.del = async (req, res) => {
console.error(new Error(err.message)); // Add to Stackdriver Error Reporting
res.status(500).send(err.message);
}
};
}
1 change: 1 addition & 0 deletions datastore/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"engines": {
"node": ">=16.0.0"
},
"type": "module",
"scripts": {
"test": "c8 mocha -p -j 2 test/*.test.js --timeout=5000"
},
Expand Down
16 changes: 8 additions & 8 deletions datastore/functions/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@

'use strict';

const assert = require('assert');
const execPromise = require('child-process-promise').exec;
const path = require('path');
const uuid = require('uuid');
const sinon = require('sinon');
const fetch = require('node-fetch');
const waitPort = require('wait-port');
const {Datastore} = require('@google-cloud/datastore');
import assert from 'assert';
import {exec as execPromise} from 'child-process-promise';
import path from 'path';
import uuid from 'uuid';
import sinon from 'sinon';
import fetch from 'node-fetch';
import waitPort from 'wait-port';
import {Datastore} from '@google-cloud/datastore';

const datastore = new Datastore();
const program = require('../');

Check failure on line 27 in datastore/functions/test/index.test.js

View workflow job for this annotation

GitHub Actions / lint

'require' is not defined
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Since you're using ES modules, you should use import instead of require here as well to be consistent.

Suggested change
const program = require('../');
import * as program from '../';


const FF_TIMEOUT = 3000;
const cwd = path.join(__dirname, '..');

Check failure on line 30 in datastore/functions/test/index.test.js

View workflow job for this annotation

GitHub Actions / lint

'__dirname' is not defined
const NAME = 'sampletask1';
const KIND = `Task-${uuid.v4()}`;
const VALUE = {
Expand Down
Loading