Open aalej opened 8 months ago
We just upgraded from an old version of the cloud SDK emulators (from http://gcr.io/google.com/cloudsdktool/cloud-sdk:412.0.0-emulators
to http://gcr.io/google.com/cloudsdktool/cloud-sdk:498.0.0-emulators
).
After switching from running the emulator via gcloud beta emulators datastore start --use-firestore-in-datastore-mode
to gcloud emulators firestore start --database-mode=datastore-mode
all of our tests have broken as the old emulator supported namespaces.
It is a shame that the native firestore emulator seems to emulate firestore less completely than the datastore emulator. It would be great if this functionality was brought to parity.
[REQUIRED] Environment info
firebase-tools: v13.6.0
Platform: macOS Sonoma 14.4
node: v20.10.0
gcloud: v470.0.0
cloud-firestore-emulator: v1.19.4
[REQUIRED] Test case
MCVE - https://github.com/aalej/issues-6932
Alternatively, make a directory containing the ff files:
src/index.ts
```ts import { Datastore } from "@google-cloud/datastore"; const datastore = new Datastore({ projectId: "some-testproject", }); export async function getNamespaces() { const query = datastore.createQuery("__namespace__").select("__key__"); const [entities] = await datastore.runQuery(query); const namespaces = entities.map((entity) => entity[datastore.KEY].name); return namespaces; } export async function addEntity(namespace: string, kind: string[], data: any) { const entityKey = datastore.key({ path: kind, namespace, }); const entity = { key: entityKey, data, }; await datastore.save(entity); } async function main() { await addEntity("Tasks", ["Work Tasks"], { category: "Personal", done: false, priority: 4, description: "Learn Cloud Datastore", }); const namespaces = await getNamespaces(); console.log(namespaces); } main(); ```tsconfig.json
```json { "compilerOptions": { "target": "es2016", "module": "commonjs", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, "outDir": "lib" }, "include": ["src"], "exclude": [] } ```package.json
```json { "version": "1.0.0", "description": "", "main": "lib/index.js", "scripts": { "build": "tsc", "build:watch": "tsc --watch" }, "devDependencies": { "@google-cloud/datastore": "^8.6.0", "typescript": "^5.4.3" } } ```[REQUIRED] Steps to reproduce
Testing while connected to the emulator
npm i
gcloud emulators firestore start --database-mode=datastore-mode --host-port=127.0.0.1:8081
export DATASTORE_EMULATOR_HOST=127.0.0.1:8081
npm run build
node .
ornode lib/index.js
[REQUIRED] Expected behavior
Console logs should show the namespaces on Datastore emulator.
When connecting to production, console logs show the namespaces on Datastore:
Steps to test on a production environment:
unset DATASTORE_EMULATOR_HOST
export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_key.json>
npm run build
node .
ornode lib/index.js
[REQUIRED] Actual behavior
When connected to the emulator, console log outputs an empty array