Is Firestore for Node.js eventually moving to the new modular v9 used in Web?

Viewed 311

Sorry if this is the wrong place to ask this, but not sure where this would go! I am building an app with Firebase Firestore and Functions and would like to use the same query snippets between the front and the backend occasionally, but now the v9 syntax is much different than the v8 syntax. Will we eventually see the same v9 syntax on the Node.js side?

Update:

Modular syntax still isn't working after updating to Node 16. Maybe my code snippet is wrong? TSLint is underlining usage of db in updateDoc() with the error:

No overload matches this call.
  Overload 1 of 3, '(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>', gave the following error.
    Argument of type 'FirebaseFirestore.Firestore' is not assignable to parameter of type 'import("C:/Users/dougl/Documents/GitHub/fire-react-base/functions/node_modules/@firebase/firestore/dist/index").Firestore'.
      Type 'Firestore' is missing the following properties from type 'Firestore': type, app, toJSON
  Overload 2 of 3, '(reference: CollectionReference<unknown>, path?: string | undefined, ...pathSegments: string[]): DocumentReference<unknown>', gave the following error.
    Argument of type 'Firestore' is not assignable to parameter of type 'CollectionReference<unknown>'.
      Type 'Firestore' is missing the following properties from type 'CollectionReference<unknown>': type, id, path, parent, and 3 more.
  Overload 3 of 3, '(reference: DocumentReference<unknown>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>', gave the following error.
    Argument of type 'Firestore' is not assignable to parameter of type 'DocumentReference<unknown>'.
      Type 'Firestore' is missing the following properties from type 'DocumentReference<unknown>': converter, type, firestore, id, and 3 more.ts(2769)

Firebase Function:

"use strict";
import functions = require("firebase-functions");
import {DocumentSnapshot, getFirestore} from "firebase-admin/firestore";
import { doc, increment, updateDoc } from "firebase/firestore"; 
import { initializeApp } from "firebase-admin";

const fire = initializeApp(functions.config().firebase);
const db = getFirestore(fire);

export const onMessageCreated = functions.firestore
    .document("messages/{messageId}")
    .onCreate(async (snap: DocumentSnapshot, context: functions.EventContext) => {
        const newValues = snap.data();
        if (!newValues) {
            return;
        } else {
            console.log("newValues: ");
            console.log(newValues);
        }

        try {
            const allPromises: Array<Promise<any>> = [];

            await updateDoc(doc(db, "site", "counts"), {
                messages: increment(1)
            }).then(() => {
                console.log(`Incremented messageCount`)
            }).catch(error => {
                console.error(`Error incrementing messageCount: ${error}`)
            })

            return Promise.all(allPromises);
        } catch (error) {
            console.error(error);
            return;
        }
});

Functions package.json:

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "16"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase": "^9.6.8",
    "firebase-admin": "^10.0.2",
    "firebase-functions": "^3.19.0"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^3.9.1",
    "@typescript-eslint/parser": "^3.8.0",
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.22.0",
    "firebase-functions-test": "^0.2.0",
    "typescript": "^4.6.2"
  },
  "private": true
}
1 Answers
Related