From fc37911f68a8402bd3b6dee8f3fc3ef4dbe69619 Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 29 Apr 2025 12:59:59 +1000 Subject: [PATCH 1/3] chore(ci): migrate datastore/functions to new ci --- .github/config/nodejs-dev.jsonc | 1 + .github/config/nodejs.jsonc | 1 - datastore/functions/index.js | 14 +++++++------- datastore/functions/package.json | 1 + datastore/functions/test/index.test.js | 16 ++++++++-------- 5 files changed, 17 insertions(+), 16 deletions(-) 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..979a8da7f1 100644 --- a/datastore/functions/test/index.test.js +++ b/datastore/functions/test/index.test.js @@ -14,14 +14,14 @@ '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('../'); From 8625401cdf01e29eb8a4cecce88dca7b5c43203a Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 29 Apr 2025 13:05:39 +1000 Subject: [PATCH 2/3] migrate --- datastore/functions/test/index.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/datastore/functions/test/index.test.js b/datastore/functions/test/index.test.js index 979a8da7f1..23170c0dd1 100644 --- a/datastore/functions/test/index.test.js +++ b/datastore/functions/test/index.test.js @@ -27,7 +27,9 @@ 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 VALUE = { From 57cd8873865afb2000d0cb6037c38e667f25c6ee Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Tue, 29 Apr 2025 13:44:38 +1000 Subject: [PATCH 3/3] update import --- datastore/functions/test/index.test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/datastore/functions/test/index.test.js b/datastore/functions/test/index.test.js index 23170c0dd1..b5d01c9857 100644 --- a/datastore/functions/test/index.test.js +++ b/datastore/functions/test/index.test.js @@ -16,8 +16,7 @@ import assert from 'assert'; import {exec as execPromise} from 'child-process-promise'; -import path from 'path'; -import uuid from 'uuid'; +import { v4 } from 'uuid'; import sinon from 'sinon'; import fetch from 'node-fetch'; import waitPort from 'wait-port'; @@ -31,7 +30,7 @@ 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', };