firebase-functions 3.24.0 → 4.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -9
- package/lib/bin/firebase-functions.js +13 -15
- package/lib/common/app.d.ts +14 -0
- package/lib/common/app.js +62 -0
- package/lib/common/change.d.ts +0 -5
- package/lib/common/change.js +5 -7
- package/lib/common/config.d.ts +6 -0
- package/lib/common/config.js +49 -0
- package/lib/common/debug.js +2 -2
- package/lib/common/encoding.d.ts +0 -8
- package/lib/common/encoding.js +6 -29
- package/lib/common/options.d.ts +14 -0
- package/lib/common/options.js +44 -0
- package/lib/common/params.d.ts +32 -0
- package/lib/common/params.js +23 -0
- package/lib/common/providers/database.d.ts +17 -19
- package/lib/common/providers/database.js +68 -39
- package/lib/common/providers/https.d.ts +11 -52
- package/lib/common/providers/https.js +115 -110
- package/lib/common/providers/identity.d.ts +8 -8
- package/lib/common/providers/identity.js +71 -79
- package/lib/common/providers/tasks.d.ts +11 -10
- package/lib/common/providers/tasks.js +10 -9
- package/lib/common/timezone.js +538 -538
- package/lib/common/trace.d.ts +14 -0
- package/lib/common/trace.js +69 -0
- package/lib/{encoder.d.ts → common/utilities/encoder.d.ts} +0 -0
- package/lib/{encoder.js → common/utilities/encoder.js} +1 -1
- package/lib/{utilities → common/utilities}/path-pattern.d.ts +0 -0
- package/lib/{utilities → common/utilities}/path-pattern.js +17 -16
- package/lib/{utilities → common/utilities}/path.d.ts +0 -0
- package/lib/{utilities → common/utilities}/path.js +5 -7
- package/lib/{utils.d.ts → common/utilities/utils.d.ts} +1 -1
- package/lib/{utils.js → common/utilities/utils.js} +18 -12
- package/lib/logger/common.d.ts +1 -3
- package/lib/logger/common.js +9 -14
- package/lib/logger/compat.js +9 -9
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +24 -30
- package/lib/{v2/params → params}/index.d.ts +22 -9
- package/lib/{v2/params → params}/index.js +22 -14
- package/lib/params/types.d.ts +180 -0
- package/lib/params/types.js +289 -0
- package/lib/runtime/loader.js +12 -14
- package/lib/runtime/manifest.d.ts +56 -24
- package/lib/runtime/manifest.js +114 -4
- package/lib/v1/cloud-functions.d.ts +232 -0
- package/lib/v1/cloud-functions.js +205 -0
- package/lib/v1/config.d.ts +8 -0
- package/lib/v1/config.js +75 -0
- package/lib/{function-builder.d.ts → v1/function-builder.d.ts} +16 -16
- package/lib/{function-builder.js → v1/function-builder.js} +56 -46
- package/lib/v1/function-configuration.d.ts +197 -0
- package/lib/v1/function-configuration.js +70 -0
- package/lib/v1/index.d.ts +20 -0
- package/lib/{index.js → v1/index.js} +5 -10
- package/lib/{providers → v1/providers}/analytics.d.ts +5 -11
- package/lib/{providers → v1/providers}/analytics.js +49 -43
- package/lib/{providers → v1/providers}/auth.d.ts +28 -18
- package/lib/{providers → v1/providers}/auth.js +45 -34
- package/lib/{providers → v1/providers}/database.d.ts +25 -42
- package/lib/{providers → v1/providers}/database.js +46 -46
- package/lib/{providers → v1/providers}/firestore.d.ts +15 -33
- package/lib/{providers → v1/providers}/firestore.js +40 -44
- package/lib/{providers → v1/providers}/https.d.ts +3 -8
- package/lib/{providers → v1/providers}/https.js +14 -22
- package/lib/{providers → v1/providers}/pubsub.d.ts +8 -16
- package/lib/{providers → v1/providers}/pubsub.js +22 -26
- package/lib/{providers → v1/providers}/remoteConfig.d.ts +2 -11
- package/lib/{providers → v1/providers}/remoteConfig.js +9 -9
- package/lib/{providers → v1/providers}/storage.d.ts +11 -26
- package/lib/{providers → v1/providers}/storage.js +24 -29
- package/lib/{providers → v1/providers}/tasks.d.ts +6 -8
- package/lib/{providers → v1/providers}/tasks.js +12 -17
- package/lib/{providers → v1/providers}/testLab.d.ts +86 -46
- package/lib/{providers → v1/providers}/testLab.js +14 -14
- package/lib/v2/core.d.ts +4 -5
- package/lib/v2/index.d.ts +16 -14
- package/lib/v2/index.js +5 -1
- package/lib/v2/options.d.ts +52 -32
- package/lib/v2/options.js +32 -47
- package/lib/v2/providers/alerts/alerts.d.ts +20 -18
- package/lib/v2/providers/alerts/alerts.js +9 -6
- package/lib/v2/providers/alerts/appDistribution.d.ts +36 -26
- package/lib/v2/providers/alerts/appDistribution.js +10 -7
- package/lib/v2/providers/alerts/billing.d.ts +5 -5
- package/lib/v2/providers/alerts/billing.js +5 -4
- package/lib/v2/providers/alerts/crashlytics.d.ts +32 -30
- package/lib/v2/providers/alerts/crashlytics.js +10 -9
- package/lib/v2/providers/alerts/index.d.ts +5 -5
- package/lib/v2/providers/alerts/performance.d.ts +15 -3
- package/lib/v2/providers/alerts/performance.js +5 -7
- package/lib/v2/providers/database.d.ts +41 -38
- package/lib/v2/providers/database.js +22 -17
- package/lib/v2/providers/eventarc.d.ts +25 -23
- package/lib/v2/providers/eventarc.js +10 -7
- package/lib/v2/providers/https.d.ts +43 -33
- package/lib/v2/providers/https.js +18 -56
- package/lib/v2/providers/identity.d.ts +25 -23
- package/lib/v2/providers/identity.js +10 -7
- package/lib/v2/providers/pubsub.d.ts +25 -23
- package/lib/v2/providers/pubsub.js +11 -27
- package/lib/v2/providers/remoteConfig.d.ts +63 -0
- package/lib/v2/providers/remoteConfig.js +65 -0
- package/lib/v2/providers/scheduler.d.ts +14 -12
- package/lib/v2/providers/scheduler.js +16 -14
- package/lib/v2/providers/storage.d.ts +32 -30
- package/lib/v2/providers/storage.js +16 -32
- package/lib/v2/providers/tasks.d.ts +30 -26
- package/lib/v2/providers/tasks.js +14 -31
- package/lib/v2/providers/testLab.d.ts +110 -0
- package/lib/v2/providers/testLab.js +65 -0
- package/lib/v2/trace.d.ts +4 -0
- package/lib/v2/trace.js +21 -0
- package/package.json +62 -67
- package/lib/apps.d.ts +0 -35
- package/lib/apps.js +0 -112
- package/lib/cloud-functions.d.ts +0 -231
- package/lib/cloud-functions.js +0 -251
- package/lib/config.d.ts +0 -24
- package/lib/config.js +0 -117
- package/lib/function-configuration.d.ts +0 -108
- package/lib/function-configuration.js +0 -71
- package/lib/handler-builder.d.ts +0 -256
- package/lib/handler-builder.js +0 -349
- package/lib/index.d.ts +0 -19
- package/lib/setup.d.ts +0 -1
- package/lib/setup.js +0 -60
- package/lib/v2/params/types.d.ts +0 -118
- package/lib/v2/params/types.js +0 -196
package/README.md
CHANGED
|
@@ -23,15 +23,13 @@ _Please avoid double posting across multiple channels!_
|
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
25
|
// functions/index.js
|
|
26
|
-
const functions = require(
|
|
27
|
-
const notifyUsers = require(
|
|
28
|
-
|
|
29
|
-
exports.newPost = functions.database
|
|
30
|
-
.
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
return notifyUsers(snapshot.val());
|
|
34
|
-
});
|
|
26
|
+
const functions = require("firebase-functions");
|
|
27
|
+
const notifyUsers = require("./notify-users");
|
|
28
|
+
|
|
29
|
+
exports.newPost = functions.database.ref("/posts/{postId}").onCreate((snapshot, context) => {
|
|
30
|
+
functions.logger.info("Received new post with ID:", context.params.postId);
|
|
31
|
+
return notifyUsers(snapshot.val());
|
|
32
|
+
});
|
|
35
33
|
```
|
|
36
34
|
|
|
37
35
|
## Contributing
|
|
@@ -34,33 +34,31 @@ Arguments:
|
|
|
34
34
|
`);
|
|
35
35
|
process.exit(1);
|
|
36
36
|
}
|
|
37
|
-
let functionsDir =
|
|
37
|
+
let functionsDir = ".";
|
|
38
38
|
const args = process.argv.slice(2);
|
|
39
39
|
if (args.length > 1) {
|
|
40
|
-
if (args[0] ===
|
|
40
|
+
if (args[0] === "-h" || args[0] === "--help") {
|
|
41
41
|
printUsageAndExit();
|
|
42
42
|
}
|
|
43
43
|
functionsDir = args[0];
|
|
44
44
|
}
|
|
45
|
-
let server;
|
|
45
|
+
let server = undefined;
|
|
46
46
|
const app = express();
|
|
47
|
-
|
|
48
|
-
res.send(
|
|
49
|
-
server.close(() => console.log(
|
|
47
|
+
function handleQuitquitquit(req, res) {
|
|
48
|
+
res.send("ok");
|
|
49
|
+
server.close(() => console.log("shutdown requested via /__/quitquitquit"));
|
|
50
50
|
}
|
|
51
|
-
app.get(
|
|
52
|
-
app.post(
|
|
53
|
-
if (process.env.FUNCTIONS_CONTROL_API ===
|
|
54
|
-
app.get(
|
|
51
|
+
app.get("/__/quitquitquit", handleQuitquitquit);
|
|
52
|
+
app.post("/__/quitquitquit", handleQuitquitquit);
|
|
53
|
+
if (process.env.FUNCTIONS_CONTROL_API === "true") {
|
|
54
|
+
app.get("/__/functions.yaml", async (req, res) => {
|
|
55
55
|
try {
|
|
56
56
|
const stack = await (0, loader_1.loadStack)(functionsDir);
|
|
57
|
-
res.setHeader(
|
|
57
|
+
res.setHeader("content-type", "text/yaml");
|
|
58
58
|
res.send(JSON.stringify((0, manifest_1.stackToWire)(stack)));
|
|
59
59
|
}
|
|
60
60
|
catch (e) {
|
|
61
|
-
res
|
|
62
|
-
.status(400)
|
|
63
|
-
.send(`Failed to generate manifest from function source: ${e}`);
|
|
61
|
+
res.status(400).send(`Failed to generate manifest from function source: ${e}`);
|
|
64
62
|
}
|
|
65
63
|
});
|
|
66
64
|
}
|
|
@@ -68,5 +66,5 @@ let port = 8080;
|
|
|
68
66
|
if (process.env.PORT) {
|
|
69
67
|
port = Number.parseInt(process.env.PORT);
|
|
70
68
|
}
|
|
71
|
-
console.log(
|
|
69
|
+
console.log("Serving at port", port);
|
|
72
70
|
server = app.listen(port);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { App } from "firebase-admin/app";
|
|
2
|
+
export declare function getApp(): App;
|
|
3
|
+
/**
|
|
4
|
+
* This function allows the Firebase Emulator Suite to override the FirebaseApp instance
|
|
5
|
+
* used by the Firebase Functions SDK. Developers should never call this function for
|
|
6
|
+
* other purposes.
|
|
7
|
+
* N.B. For clarity for use in testing this name has no mention of emulation, but
|
|
8
|
+
* it must be exported from index as app.setEmulatedAdminApp or we break the emulator.
|
|
9
|
+
* We can remove this export when:
|
|
10
|
+
* A) We complete the new emulator and no longer depend on monkeypatching
|
|
11
|
+
* B) We tweak the CLI to look for different APIs to monkeypatch depending on versions.
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
14
|
+
export declare function setApp(app?: App): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2017 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.setApp = exports.getApp = void 0;
|
|
25
|
+
const app_1 = require("firebase-admin/app");
|
|
26
|
+
const config_1 = require("./config");
|
|
27
|
+
const APP_NAME = "__FIREBASE_FUNCTIONS_SDK__";
|
|
28
|
+
let cache;
|
|
29
|
+
function getApp() {
|
|
30
|
+
if (typeof cache === "undefined") {
|
|
31
|
+
try {
|
|
32
|
+
cache = (0, app_1.getApp)( /* default */);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Default app does not exist. Initialize app.
|
|
36
|
+
cache = (0, app_1.initializeApp)({
|
|
37
|
+
...(0, config_1.firebaseConfig)(),
|
|
38
|
+
credential: (0, app_1.applicationDefault)(),
|
|
39
|
+
}, APP_NAME);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return cache;
|
|
43
|
+
}
|
|
44
|
+
exports.getApp = getApp;
|
|
45
|
+
/**
|
|
46
|
+
* This function allows the Firebase Emulator Suite to override the FirebaseApp instance
|
|
47
|
+
* used by the Firebase Functions SDK. Developers should never call this function for
|
|
48
|
+
* other purposes.
|
|
49
|
+
* N.B. For clarity for use in testing this name has no mention of emulation, but
|
|
50
|
+
* it must be exported from index as app.setEmulatedAdminApp or we break the emulator.
|
|
51
|
+
* We can remove this export when:
|
|
52
|
+
* A) We complete the new emulator and no longer depend on monkeypatching
|
|
53
|
+
* B) We tweak the CLI to look for different APIs to monkeypatch depending on versions.
|
|
54
|
+
* @alpha
|
|
55
|
+
*/
|
|
56
|
+
function setApp(app) {
|
|
57
|
+
if ((cache === null || cache === void 0 ? void 0 : cache.name) === APP_NAME) {
|
|
58
|
+
void (0, app_1.deleteApp)(cache);
|
|
59
|
+
}
|
|
60
|
+
cache = app;
|
|
61
|
+
}
|
|
62
|
+
exports.setApp = setApp;
|
package/lib/common/change.d.ts
CHANGED
|
@@ -12,13 +12,10 @@ export interface ChangeJson {
|
|
|
12
12
|
*/
|
|
13
13
|
before?: any;
|
|
14
14
|
/**
|
|
15
|
-
* @hidden
|
|
16
15
|
* Comma-separated string that represents names of fields that changed.
|
|
17
16
|
*/
|
|
18
17
|
fieldMask?: string;
|
|
19
18
|
}
|
|
20
|
-
/** @hidden */
|
|
21
|
-
export declare function applyFieldMask(sparseBefore: any, after: any, fieldMask: string): any;
|
|
22
19
|
/**
|
|
23
20
|
* The Functions interface for events that change state, such as
|
|
24
21
|
* Realtime Database or Cloud Firestore `onWrite` and `onUpdate`.
|
|
@@ -31,13 +28,11 @@ export declare class Change<T> {
|
|
|
31
28
|
before: T;
|
|
32
29
|
after: T;
|
|
33
30
|
/**
|
|
34
|
-
* @hidden
|
|
35
31
|
* Factory method for creating a Change from a `before` object and an `after`
|
|
36
32
|
* object.
|
|
37
33
|
*/
|
|
38
34
|
static fromObjects<T>(before: T, after: T): Change<T>;
|
|
39
35
|
/**
|
|
40
|
-
* @hidden
|
|
41
36
|
* Factory method for creating a Change from a JSON and an optional customizer
|
|
42
37
|
* function to be applied to both the `before` and the `after` fields.
|
|
43
38
|
*/
|
package/lib/common/change.js
CHANGED
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.Change = exports.applyFieldMask = void 0;
|
|
25
|
-
/** @
|
|
25
|
+
/** @internal */
|
|
26
26
|
function applyFieldMask(sparseBefore, after, fieldMask) {
|
|
27
27
|
const before = { ...after };
|
|
28
|
-
const masks = fieldMask.split(
|
|
28
|
+
const masks = fieldMask.split(",");
|
|
29
29
|
for (const mask of masks) {
|
|
30
|
-
const parts = mask.split(
|
|
30
|
+
const parts = mask.split(".");
|
|
31
31
|
const head = parts[0];
|
|
32
|
-
const tail = parts.slice(1).join(
|
|
32
|
+
const tail = parts.slice(1).join(".");
|
|
33
33
|
if (parts.length > 1) {
|
|
34
34
|
before[head] = applyFieldMask(sparseBefore === null || sparseBefore === void 0 ? void 0 : sparseBefore[head], after[head], tail);
|
|
35
35
|
continue;
|
|
36
36
|
}
|
|
37
37
|
const val = sparseBefore === null || sparseBefore === void 0 ? void 0 : sparseBefore[head];
|
|
38
|
-
if (typeof val ===
|
|
38
|
+
if (typeof val === "undefined") {
|
|
39
39
|
delete before[mask];
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
@@ -59,7 +59,6 @@ class Change {
|
|
|
59
59
|
this.after = after;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* @hidden
|
|
63
62
|
* Factory method for creating a Change from a `before` object and an `after`
|
|
64
63
|
* object.
|
|
65
64
|
*/
|
|
@@ -67,7 +66,6 @@ class Change {
|
|
|
67
66
|
return new Change(before, after);
|
|
68
67
|
}
|
|
69
68
|
/**
|
|
70
|
-
* @hidden
|
|
71
69
|
* Factory method for creating a Change from a JSON and an optional customizer
|
|
72
70
|
* function to be applied to both the `before` and the `after` fields.
|
|
73
71
|
*/
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.firebaseConfig = exports.resetCache = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const logger = require("../logger");
|
|
7
|
+
let cache = null;
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
* @alpha
|
|
11
|
+
*/
|
|
12
|
+
function resetCache(newCache = null) {
|
|
13
|
+
cache = newCache;
|
|
14
|
+
}
|
|
15
|
+
exports.resetCache = resetCache;
|
|
16
|
+
/**
|
|
17
|
+
* Get the fields you need to initialize a Firebase app
|
|
18
|
+
* @alpha
|
|
19
|
+
*/
|
|
20
|
+
function firebaseConfig() {
|
|
21
|
+
if (cache) {
|
|
22
|
+
return cache;
|
|
23
|
+
}
|
|
24
|
+
let env = process.env.FIREBASE_CONFIG;
|
|
25
|
+
if (env) {
|
|
26
|
+
// Firebase Tools will always use a JSON blob in prod, but docs
|
|
27
|
+
// explicitly state that the user can set the env to a file:
|
|
28
|
+
// https://firebase.google.com/docs/admin/setup#initialize-without-parameters
|
|
29
|
+
if (!env.startsWith("{")) {
|
|
30
|
+
env = (0, fs_1.readFileSync)(path.join(process.env.PWD, env)).toString("utf8");
|
|
31
|
+
}
|
|
32
|
+
cache = JSON.parse(env);
|
|
33
|
+
return cache;
|
|
34
|
+
}
|
|
35
|
+
if (process.env.GCLOUD_PROJECT) {
|
|
36
|
+
logger.warn("Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail");
|
|
37
|
+
cache = {
|
|
38
|
+
databaseURL: process.env.DATABASE_URL || `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
|
|
39
|
+
storageBucket: process.env.STORAGE_BUCKET_URL || `${process.env.GCLOUD_PROJECT}.appspot.com`,
|
|
40
|
+
projectId: process.env.GCLOUD_PROJECT,
|
|
41
|
+
};
|
|
42
|
+
return cache;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
logger.warn("Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail");
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
exports.firebaseConfig = firebaseConfig;
|
package/lib/common/debug.js
CHANGED
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.isDebugFeatureEnabled = exports.debugFeatureValue = void 0;
|
|
25
25
|
// Do NOT turn on a debug feature in production.
|
|
26
|
-
const debugMode = process.env.FIREBASE_DEBUG_MODE ===
|
|
26
|
+
const debugMode = process.env.FIREBASE_DEBUG_MODE === "true";
|
|
27
27
|
function loadDebugFeatures() {
|
|
28
28
|
if (!debugMode) {
|
|
29
29
|
return {};
|
|
30
30
|
}
|
|
31
31
|
try {
|
|
32
32
|
const obj = JSON.parse(process.env.FIREBASE_DEBUG_FEATURES);
|
|
33
|
-
if (typeof obj !==
|
|
33
|
+
if (typeof obj !== "object") {
|
|
34
34
|
return {};
|
|
35
35
|
}
|
|
36
36
|
return obj;
|
package/lib/common/encoding.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A type alias used to annotate interfaces as using a google.protobuf.Duration.
|
|
3
|
-
* This type is parsed/encoded as a string of seconds + the "s" prefix.
|
|
4
|
-
*/
|
|
5
|
-
export declare type Duration = string;
|
|
6
|
-
/** Get a google.protobuf.Duration for a number of seconds. */
|
|
7
|
-
export declare function durationFromSeconds(s: number): Duration;
|
|
8
1
|
/**
|
|
9
2
|
* Utility function to help copy fields from type A to B.
|
|
10
3
|
* As a safety net, catches typos or fields that aren't named the same
|
|
@@ -12,5 +5,4 @@ export declare function durationFromSeconds(s: number): Duration;
|
|
|
12
5
|
*/
|
|
13
6
|
export declare function copyIfPresent<Src, Dest>(dest: Dest, src: Src, ...fields: Array<keyof Src & keyof Dest>): void;
|
|
14
7
|
export declare function convertIfPresent<Src, Dest>(dest: Dest, src: Src, destField: keyof Dest, srcField: keyof Src, converter?: (from: any) => any): void;
|
|
15
|
-
export declare function serviceAccountFromShorthand(serviceAccount: string): string | null;
|
|
16
8
|
export declare function convertInvoker(invoker: string | string[]): string[];
|
package/lib/common/encoding.js
CHANGED
|
@@ -21,12 +21,8 @@
|
|
|
21
21
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.convertInvoker = exports.
|
|
25
|
-
|
|
26
|
-
function durationFromSeconds(s) {
|
|
27
|
-
return `${s}s`;
|
|
28
|
-
}
|
|
29
|
-
exports.durationFromSeconds = durationFromSeconds;
|
|
24
|
+
exports.convertInvoker = exports.convertIfPresent = exports.copyIfPresent = void 0;
|
|
25
|
+
// Copied from firebase-tools/src/gcp/proto
|
|
30
26
|
/**
|
|
31
27
|
* Utility function to help copy fields from type A to B.
|
|
32
28
|
* As a safety net, catches typos or fields that aren't named the same
|
|
@@ -56,36 +52,17 @@ function convertIfPresent(dest, src, destField, srcField, converter = (from) =>
|
|
|
56
52
|
dest[destField] = converter(src[srcField]);
|
|
57
53
|
}
|
|
58
54
|
exports.convertIfPresent = convertIfPresent;
|
|
59
|
-
function serviceAccountFromShorthand(serviceAccount) {
|
|
60
|
-
if (serviceAccount === 'default') {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
else if (serviceAccount.endsWith('@')) {
|
|
64
|
-
if (!process.env.GCLOUD_PROJECT) {
|
|
65
|
-
throw new Error(`Unable to determine email for service account '${serviceAccount}' because process.env.GCLOUD_PROJECT is not set.`);
|
|
66
|
-
}
|
|
67
|
-
return `${serviceAccount}${process.env.GCLOUD_PROJECT}.iam.gserviceaccount.com`;
|
|
68
|
-
}
|
|
69
|
-
else if (serviceAccount.includes('@')) {
|
|
70
|
-
return serviceAccount;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
throw new Error(`Invalid option for serviceAccount: '${serviceAccount}'. Valid options are 'default', a service account email, or '{serviceAccountName}@'`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.serviceAccountFromShorthand = serviceAccountFromShorthand;
|
|
77
55
|
function convertInvoker(invoker) {
|
|
78
|
-
if (typeof invoker ===
|
|
56
|
+
if (typeof invoker === "string") {
|
|
79
57
|
invoker = [invoker];
|
|
80
58
|
}
|
|
81
59
|
if (invoker.length === 0) {
|
|
82
|
-
throw new Error(
|
|
60
|
+
throw new Error("Invalid option for invoker: Must be a non-empty array.");
|
|
83
61
|
}
|
|
84
62
|
if (invoker.find((inv) => inv.length === 0)) {
|
|
85
|
-
throw new Error(
|
|
63
|
+
throw new Error("Invalid option for invoker: Must be a non-empty string.");
|
|
86
64
|
}
|
|
87
|
-
if (invoker.length > 1 &&
|
|
88
|
-
invoker.find((inv) => inv === 'public' || inv === 'private')) {
|
|
65
|
+
if (invoker.length > 1 && invoker.find((inv) => inv === "public" || inv === "private")) {
|
|
89
66
|
throw new Error("Invalid option for invoker: Cannot have 'public' or 'private' in an array of service accounts.");
|
|
90
67
|
}
|
|
91
68
|
return invoker;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Special configuration type to reset configuration to platform default.
|
|
3
|
+
*
|
|
4
|
+
* @alpha
|
|
5
|
+
*/
|
|
6
|
+
export declare class ResetValue {
|
|
7
|
+
toJSON(): null;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(): ResetValue;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Special configuration value to reset configuration to platform default.
|
|
13
|
+
*/
|
|
14
|
+
export declare const RESET_VALUE: ResetValue;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RESET_VALUE = exports.ResetValue = void 0;
|
|
4
|
+
// The MIT License (MIT)
|
|
5
|
+
//
|
|
6
|
+
// Copyright (c) 2022 Firebase
|
|
7
|
+
//
|
|
8
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
// in the Software without restriction, including without limitation the rights
|
|
11
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
// furnished to do so, subject to the following conditions:
|
|
14
|
+
//
|
|
15
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
// copies or substantial portions of the Software.
|
|
17
|
+
//
|
|
18
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
// SOFTWARE.
|
|
25
|
+
/**
|
|
26
|
+
* Special configuration type to reset configuration to platform default.
|
|
27
|
+
*
|
|
28
|
+
* @alpha
|
|
29
|
+
*/
|
|
30
|
+
class ResetValue {
|
|
31
|
+
toJSON() {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
35
|
+
constructor() { }
|
|
36
|
+
static getInstance() {
|
|
37
|
+
return new ResetValue();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.ResetValue = ResetValue;
|
|
41
|
+
/**
|
|
42
|
+
* Special configuration value to reset configuration to platform default.
|
|
43
|
+
*/
|
|
44
|
+
exports.RESET_VALUE = ResetValue.getInstance();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type that splits literal string S with delimiter D.
|
|
3
|
+
*
|
|
4
|
+
* For example Split<"a/b/c", "/"> is ['a' | "b" | "c"]
|
|
5
|
+
*/
|
|
6
|
+
export declare type Split<S extends string, D extends string> = string extends S ? string[] : S extends "" ? [] : S extends `${D}${infer Tail}` ? [...Split<Tail, D>] : S extends `${infer Head}${D}${infer Tail}` ? string extends Head ? [...Split<Tail, D>] : [Head, ...Split<Tail, D>] : [
|
|
7
|
+
S
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* A type that ensure that type S is not null or undefined.
|
|
11
|
+
*/
|
|
12
|
+
export declare type NullSafe<S extends null | undefined | string> = S extends null ? never : S extends undefined ? never : S extends string ? S : never;
|
|
13
|
+
/**
|
|
14
|
+
* A type that extracts parameter name enclosed in bracket as string.
|
|
15
|
+
* Ignore wildcard matches
|
|
16
|
+
*
|
|
17
|
+
* For example, Extract<"{uid}"> is "uid".
|
|
18
|
+
* For example, Extract<"{uid=*}"> is "uid".
|
|
19
|
+
* For example, Extract<"{uid=**}"> is "uid".
|
|
20
|
+
*/
|
|
21
|
+
export declare type Extract<Part extends string> = Part extends `{${infer Param}=**}` ? Param : Part extends `{${infer Param}=*}` ? Param : Part extends `{${infer Param}}` ? Param : never;
|
|
22
|
+
/**
|
|
23
|
+
* A type that maps all parameter capture gropus into keys of a record.
|
|
24
|
+
* For example, ParamsOf<"users/{uid}"> is { uid: string }
|
|
25
|
+
* ParamsOf<"users/{uid}/logs/{log}"> is { uid: string; log: string }
|
|
26
|
+
* ParamsOf<"some/static/data"> is {}
|
|
27
|
+
*
|
|
28
|
+
* For flexibility reasons, ParamsOf<string> is Record<string, string>
|
|
29
|
+
*/
|
|
30
|
+
export declare type ParamsOf<PathPattern extends string> = string extends PathPattern ? Record<string, string> : {
|
|
31
|
+
[Key in Extract<Split<NullSafe<PathPattern>, "/">[number]>]: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2021 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { App } from "firebase-admin/app";
|
|
2
|
+
import * as database from "firebase-admin/database";
|
|
2
3
|
/**
|
|
3
|
-
* Interface representing a Firebase Realtime
|
|
4
|
+
* Interface representing a Firebase Realtime database data snapshot.
|
|
4
5
|
*/
|
|
5
|
-
export declare class DataSnapshot {
|
|
6
|
+
export declare class DataSnapshot implements database.DataSnapshot {
|
|
6
7
|
private app?;
|
|
7
8
|
instance: string;
|
|
8
9
|
/** @hidden */
|
|
@@ -13,23 +14,23 @@ export declare class DataSnapshot {
|
|
|
13
14
|
private _data;
|
|
14
15
|
/** @hidden */
|
|
15
16
|
private _childPath;
|
|
16
|
-
constructor(data: any, path?: string, // path
|
|
17
|
-
app?:
|
|
17
|
+
constructor(data: any, path?: string, // path is undefined for the database root
|
|
18
|
+
app?: App, instance?: string);
|
|
18
19
|
/**
|
|
19
20
|
* Returns a [`Reference`](/docs/reference/admin/node/admin.database.Reference)
|
|
20
|
-
* to the
|
|
21
|
+
* to the database location where the triggering write occurred. Has
|
|
21
22
|
* full read and write access.
|
|
22
23
|
*/
|
|
23
|
-
get ref():
|
|
24
|
+
get ref(): database.Reference;
|
|
24
25
|
/**
|
|
25
26
|
* The key (last part of the path) of the location of this `DataSnapshot`.
|
|
26
27
|
*
|
|
27
|
-
* The last token in a
|
|
28
|
+
* The last token in a database location is considered its key. For example,
|
|
28
29
|
* "ada" is the key for the `/users/ada/` node. Accessing the key on any
|
|
29
|
-
* `DataSnapshot`
|
|
30
|
-
* However, accessing the key on the root URL of a
|
|
30
|
+
* `DataSnapshot` returns the key for the location that generated it.
|
|
31
|
+
* However, accessing the key on the root URL of a database returns `null`.
|
|
31
32
|
*/
|
|
32
|
-
get key(): string;
|
|
33
|
+
get key(): string | null;
|
|
33
34
|
/**
|
|
34
35
|
* Extracts a JavaScript value from a `DataSnapshot`.
|
|
35
36
|
*
|
|
@@ -38,16 +39,13 @@ export declare class DataSnapshot {
|
|
|
38
39
|
* return `null`, indicating that the `DataSnapshot` is empty (contains no
|
|
39
40
|
* data).
|
|
40
41
|
*
|
|
41
|
-
* @return The
|
|
42
|
+
* @return The snapshot's contents as a JavaScript value (Object,
|
|
42
43
|
* Array, string, number, boolean, or `null`).
|
|
43
44
|
*/
|
|
44
45
|
val(): any;
|
|
45
46
|
/**
|
|
46
47
|
* Exports the entire contents of the `DataSnapshot` as a JavaScript object.
|
|
47
48
|
*
|
|
48
|
-
* The `exportVal()` method is similar to `val()`, except priority information
|
|
49
|
-
* is included (if available), making it suitable for backing up your data.
|
|
50
|
-
*
|
|
51
49
|
* @return The contents of the `DataSnapshot` as a JavaScript value
|
|
52
50
|
* (Object, Array, string, number, boolean, or `null`).
|
|
53
51
|
*/
|
|
@@ -87,13 +85,13 @@ export declare class DataSnapshot {
|
|
|
87
85
|
* JavaScript object returned by `val()` is not guaranteed to match the ordering
|
|
88
86
|
* on the server nor the ordering of `child_added` events. That is where
|
|
89
87
|
* `forEach()` comes in handy. It guarantees the children of a `DataSnapshot`
|
|
90
|
-
*
|
|
88
|
+
* can be iterated in their query order.
|
|
91
89
|
*
|
|
92
90
|
* If no explicit `orderBy*()` method is used, results are returned
|
|
93
91
|
* ordered by key (unless priorities are used, in which case, results are
|
|
94
92
|
* returned by priority).
|
|
95
93
|
*
|
|
96
|
-
* @param action A function that
|
|
94
|
+
* @param action A function that is called for each child `DataSnapshot`.
|
|
97
95
|
* The callback can return `true` to cancel further enumeration.
|
|
98
96
|
*
|
|
99
97
|
* @return `true` if enumeration was canceled due to your callback
|
|
@@ -115,7 +113,7 @@ export declare class DataSnapshot {
|
|
|
115
113
|
* You can use `hasChildren()` to determine if a `DataSnapshot` has any
|
|
116
114
|
* children. If it does, you can enumerate them using `forEach()`. If it
|
|
117
115
|
* doesn't, then either this snapshot contains a primitive value (which can be
|
|
118
|
-
* retrieved with `val()`) or it is empty (in which case, `val()`
|
|
116
|
+
* retrieved with `val()`) or it is empty (in which case, `val()` returns
|
|
119
117
|
* `null`).
|
|
120
118
|
*
|
|
121
119
|
* @return `true` if this snapshot has any children; else `false`.
|
|
@@ -132,7 +130,7 @@ export declare class DataSnapshot {
|
|
|
132
130
|
*
|
|
133
131
|
* @return A JSON-serializable representation of this object.
|
|
134
132
|
*/
|
|
135
|
-
toJSON():
|
|
133
|
+
toJSON(): Record<string, unknown>;
|
|
136
134
|
/** Recursive function to check if keys are numeric & convert node object to array if they are
|
|
137
135
|
*
|
|
138
136
|
* @hidden
|