diff --git a/README.md b/README.md index 60df9c4d4..4a7e63d65 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,13 @@ _Please avoid double posting across multiple channels!_ ```js // functions/index.js -const functions = require("firebase-functions"); +const { onValueCreated } = require("firebase-functions/database"); +const logger = require("firebase-functions/logger"); const notifyUsers = require("./notify-users"); -exports.newPost = functions.database.ref("/posts/{postId}").onCreate((snapshot, context) => { - functions.logger.info("Received new post with ID:", context.params.postId); - return notifyUsers(snapshot.val()); +exports.newPost = onValueCreated({ ref: "/posts/{postId}" }, (event) => { + logger.info("Received new post with ID:", event.params.postId); + return notifyUsers(event.data.val()); }); ``` diff --git a/package.json b/package.json index c2045687f..8c7124b82 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,12 @@ "lib", "protos" ], - "main": "lib/v1/index.js", + "main": "lib/v2/index.js", "bin": { "firebase-functions": "./lib/bin/firebase-functions.js" }, - "types": "lib/v1/index.d.ts", + "types": "lib/v2/index.d.ts", "exports": { - ".": "./lib/v1/index.js", "./logger/compat": "./lib/logger/compat.js", "./logger": "./lib/logger/index.js", "./params": "./lib/params/index.js", @@ -43,6 +42,25 @@ "./v1/storage": "./lib/v1/providers/storage.js", "./v1/tasks": "./lib/v1/providers/tasks.js", "./v1/testLab": "./lib/v1/providers/testLab.js", + ".": "./lib/v2/index.js", + "./core": "./lib/v2/core.js", + "./options": "./lib/v2/options.js", + "./https": "./lib/v2/providers/https.js", + "./pubsub": "./lib/v2/providers/pubsub.js", + "./storage": "./lib/v2/providers/storage.js", + "./tasks": "./lib/v2/providers/tasks.js", + "./alerts": "./lib/v2/providers/alerts/index.js", + "./alerts/appDistribution": "./lib/v2/providers/alerts/appDistribution.js", + "./alerts/billing": "./lib/v2/providers/alerts/billing.js", + "./alerts/crashlytics": "./lib/v2/providers/alerts/crashlytics.js", + "./alerts/performance": "./lib/v2/providers/alerts/performance.js", + "./eventarc": "./lib/v2/providers/eventarc.js", + "./identity": "./lib/v2/providers/identity.js", + "./database": "./lib/v2/providers/database.js", + "./scheduler": "./lib/v2/providers/scheduler.js", + "./remoteConfig": "./lib/v2/providers/remoteConfig.js", + "./testLab": "./lib/v2/providers/testLab.js", + "./firestore": "./lib/v2/providers/firestore.js", "./v2": "./lib/v2/index.js", "./v2/core": "./lib/v2/core.js", "./v2/options": "./lib/v2/options.js", @@ -107,6 +125,60 @@ "v1/testLab": [ "lib/v1/providers/testLab" ], + "core": [ + "./lib/v2/core" + ], + "options": [ + "./lib/v2/options" + ], + "https": [ + "./lib/v2/providers/https" + ], + "pubsub": [ + "./lib/v2/providers/pubsub" + ], + "storage": [ + "./lib/v2/providers/storage" + ], + "tasks": [ + "./lib/v2/providers/tasks" + ], + "alerts": [ + "./lib/v2/providers/alerts/index" + ], + "alerts/appDistribution": [ + "./lib/v2/providers/alerts/appDistribution" + ], + "alerts/billing": [ + "./lib/v2/providers/alerts/billing" + ], + "alerts/crashlytics": [ + "./lib/v2/providers/alerts/crashlytics" + ], + "alerts/performance": [ + "./lib/v2/providers/alerts/performance" + ], + "eventarc": [ + "./lib/v2/providers/eventarc" + ], + "identity": [ + "./lib/v2/providers/identity" + ], + "database": [ + "./lib/v2/providers/database" + ], + "scheduler": [ + "./lib/v2/providers/scheduler" + ], + "remoteConfig": [ + "./lib/v2/providers/remoteConfig" + ], + "testLab": [ + "./lib/v2/providers/testLab" + ], + "firestore": [ + "./lib/v2/providers/firestore" + ], "v2": [ "lib/v2" ], @@ -252,4 +324,4 @@ "engines": { "node": ">=14.10.0" } -} +} \ No newline at end of file diff --git a/scripts/bin-test/sources/commonjs-grouped/g1.js b/scripts/bin-test/sources/commonjs-grouped/g1.js index 57766af02..f204e44d4 100644 --- a/scripts/bin-test/sources/commonjs-grouped/g1.js +++ b/scripts/bin-test/sources/commonjs-grouped/g1.js @@ -1,4 +1,4 @@ -const functions = require("firebase-functions"); +const functions = require("firebase-functions/v1"); exports.groupedhttp = functions.https.onRequest((req, resp) => { resp.status(200).send("PASS"); diff --git a/scripts/bin-test/sources/commonjs-grouped/index.js b/scripts/bin-test/sources/commonjs-grouped/index.js index 022374a65..6d8540915 100644 --- a/scripts/bin-test/sources/commonjs-grouped/index.js +++ b/scripts/bin-test/sources/commonjs-grouped/index.js @@ -1,4 +1,4 @@ -const functions = require("firebase-functions"); +const functions = require("firebase-functions/v1"); const functionsv2 = require("firebase-functions/v2"); const firestoreTranslateText = require("@firebase-extensions/firebase-firestore-translate-text-sdk").firestoreTranslateText; const backfill = require("@firebase-extensions/local-backfill-sdk").backfill; diff --git a/scripts/bin-test/sources/commonjs-main/functions.js b/scripts/bin-test/sources/commonjs-main/functions.js index 031e109d7..dd651bf6d 100644 --- a/scripts/bin-test/sources/commonjs-main/functions.js +++ b/scripts/bin-test/sources/commonjs-main/functions.js @@ -1,4 +1,4 @@ -const functions = require("firebase-functions"); +const functions = require("firebase-functions/v1"); const functionsv2 = require("firebase-functions/v2"); const firestoreTranslateText = require("@firebase-extensions/firebase-firestore-translate-text-sdk").firestoreTranslateText; const backfill = require("@firebase-extensions/local-backfill-sdk").backfill; diff --git a/scripts/bin-test/sources/commonjs-preserve/index.js b/scripts/bin-test/sources/commonjs-preserve/index.js index 768fb6c4e..1aa98e117 100644 --- a/scripts/bin-test/sources/commonjs-preserve/index.js +++ b/scripts/bin-test/sources/commonjs-preserve/index.js @@ -1,4 +1,4 @@ -const functions = require("firebase-functions"); +const functions = require("firebase-functions/v1"); const functionsv2 = require("firebase-functions/v2"); const firestoreTranslateText = require("@firebase-extensions/firebase-firestore-translate-text-sdk").firestoreTranslateText; const backfill = require("@firebase-extensions/local-backfill-sdk").backfill; diff --git a/scripts/bin-test/sources/commonjs/index.js b/scripts/bin-test/sources/commonjs/index.js index 031e109d7..dd651bf6d 100644 --- a/scripts/bin-test/sources/commonjs/index.js +++ b/scripts/bin-test/sources/commonjs/index.js @@ -1,4 +1,4 @@ -const functions = require("firebase-functions"); +const functions = require("firebase-functions/v1"); const functionsv2 = require("firebase-functions/v2"); const firestoreTranslateText = require("@firebase-extensions/firebase-firestore-translate-text-sdk").firestoreTranslateText; const backfill = require("@firebase-extensions/local-backfill-sdk").backfill; diff --git a/scripts/bin-test/sources/esm-ext/index.mjs b/scripts/bin-test/sources/esm-ext/index.mjs index 5413b5fa2..8986236b7 100644 --- a/scripts/bin-test/sources/esm-ext/index.mjs +++ b/scripts/bin-test/sources/esm-ext/index.mjs @@ -1,4 +1,4 @@ -import * as functions from "firebase-functions"; +import * as functions from "firebase-functions/v1"; import * as functionsv2 from "firebase-functions/v2"; import { firestoreTranslateText } from "@firebase-extensions/firebase-firestore-translate-text-sdk"; import { backfill } from "@firebase-extensions/local-backfill-sdk"; diff --git a/scripts/bin-test/sources/esm-main/functions.js b/scripts/bin-test/sources/esm-main/functions.js index 3515c2124..55186cc26 100644 --- a/scripts/bin-test/sources/esm-main/functions.js +++ b/scripts/bin-test/sources/esm-main/functions.js @@ -1,4 +1,4 @@ -import * as functions from "firebase-functions"; +import * as functions from "firebase-functions/v1"; import * as functionsv2 from "firebase-functions/v2"; import { firestoreTranslateText } from "@firebase-extensions/firebase-firestore-translate-text-sdk"; import { backfill } from "@firebase-extensions/local-backfill-sdk"; diff --git a/scripts/bin-test/sources/esm/index.js b/scripts/bin-test/sources/esm/index.js index 3515c2124..55186cc26 100644 --- a/scripts/bin-test/sources/esm/index.js +++ b/scripts/bin-test/sources/esm/index.js @@ -1,4 +1,4 @@ -import * as functions from "firebase-functions"; +import * as functions from "firebase-functions/v1"; import * as functionsv2 from "firebase-functions/v2"; import { firestoreTranslateText } from "@firebase-extensions/firebase-firestore-translate-text-sdk"; import { backfill } from "@firebase-extensions/local-backfill-sdk";