diff --git a/.github/config/nodejs-dev.jsonc b/.github/config/nodejs-dev.jsonc index c8ca78b18b..8b33112b01 100644 --- a/.github/config/nodejs-dev.jsonc +++ b/.github/config/nodejs-dev.jsonc @@ -117,6 +117,7 @@ "datacatalog/quickstart", "datacatalog/snippets", "datalabeling", + "datastore/functions", "dialogflow", "discoveryengine", "document-warehouse", diff --git a/.github/config/nodejs.jsonc b/.github/config/nodejs.jsonc index b8bc67ffcb..c94bd6d0d7 100644 --- a/.github/config/nodejs.jsonc +++ b/.github/config/nodejs.jsonc @@ -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 diff --git a/datastore/functions/index.js b/datastore/functions/index.js index 35f30da559..f9a1c288fa 100644 --- a/datastore/functions/index.js +++ b/datastore/functions/index.js @@ -14,7 +14,7 @@ 'use strict'; -const {Datastore} = require('@google-cloud/datastore'); +import {Datastore} from '@google-cloud/datastore'; // Instantiates a client const datastore = new Datastore(); @@ -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) { // The value contains a JSON document representing the entity we want to save if (!req.body.value) { const err = makeErrorObj('Value'); @@ -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. @@ -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) { try { const key = await getKeyFromRequestData(req.body); const [entity] = await datastore.get(key); @@ -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. @@ -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) { // Deletes the entity // The delete operation will not fail for a non-existent entity, it just // doesn't delete anything @@ -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); } -}; +} diff --git a/datastore/functions/package.json b/datastore/functions/package.json index 38aca02bee..98ad1efbf8 100644 --- a/datastore/functions/package.json +++ b/datastore/functions/package.json @@ -10,6 +10,7 @@ "engines": { "node": ">=16.0.0" }, + "type": "module", "scripts": { "test": "c8 mocha -p -j 2 test/*.test.js --timeout=5000" }, diff --git a/datastore/functions/test/index.test.js b/datastore/functions/test/index.test.js index b683d8ffbb..b5d01c9857 100644 --- a/datastore/functions/test/index.test.js +++ b/datastore/functions/test/index.test.js @@ -14,22 +14,23 @@ '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 { v4 } 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('../'); const FF_TIMEOUT = 3000; -const cwd = path.join(__dirname, '..'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const cwd = join(__dirname, '..'); const NAME = 'sampletask1'; -const KIND = `Task-${uuid.v4()}`; +const KIND = `Task-${v4()}`; const VALUE = { description: 'Buy milk', };