firebase-functions 6.6.0 → 7.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/lib/_virtual/rolldown_runtime.js +34 -0
- package/lib/bin/firebase-functions.js +78 -103
- package/lib/common/app.js +35 -55
- package/lib/common/change.js +54 -75
- package/lib/common/config.js +41 -41
- package/lib/common/debug.js +23 -47
- package/lib/common/encoding.js +59 -82
- package/lib/common/onInit.js +26 -28
- package/lib/common/options.js +22 -42
- package/lib/common/params.d.ts +6 -6
- package/lib/common/params.js +0 -23
- package/lib/common/providers/database.js +270 -300
- package/lib/common/providers/firestore.js +66 -92
- package/lib/common/providers/https.d.ts +0 -1
- package/lib/common/providers/https.js +537 -539
- package/lib/common/providers/identity.js +393 -444
- package/lib/common/providers/tasks.js +64 -98
- package/lib/common/timezone.js +544 -542
- package/lib/common/trace.d.ts +0 -1
- package/lib/common/trace.js +63 -55
- package/lib/common/utilities/assertions.d.ts +11 -0
- package/lib/common/utilities/assertions.js +18 -0
- package/lib/common/utilities/encoder.js +20 -37
- package/lib/common/utilities/path-pattern.js +106 -132
- package/lib/common/utilities/path.js +28 -27
- package/lib/common/utilities/utils.js +23 -45
- package/lib/esm/_virtual/rolldown_runtime.mjs +16 -0
- package/lib/esm/bin/firebase-functions.mjs +91 -0
- package/lib/esm/common/app.mjs +39 -0
- package/lib/esm/common/change.mjs +57 -0
- package/lib/esm/common/config.mjs +45 -0
- package/lib/esm/common/debug.mjs +28 -0
- package/lib/esm/common/encoding.mjs +69 -0
- package/lib/esm/common/onInit.mjs +33 -0
- package/lib/esm/common/options.mjs +22 -0
- package/lib/esm/common/params.mjs +1 -0
- package/lib/esm/common/providers/database.mjs +269 -0
- package/lib/esm/common/providers/firestore.mjs +78 -0
- package/lib/esm/common/providers/https.mjs +573 -0
- package/lib/esm/common/providers/identity.mjs +428 -0
- package/lib/esm/common/providers/tasks.mjs +67 -0
- package/lib/esm/common/timezone.mjs +544 -0
- package/lib/esm/common/trace.mjs +73 -0
- package/lib/esm/common/utilities/assertions.mjs +17 -0
- package/lib/esm/common/utilities/encoder.mjs +21 -0
- package/lib/esm/common/utilities/path-pattern.mjs +116 -0
- package/lib/esm/common/utilities/path.mjs +35 -0
- package/lib/esm/common/utilities/utils.mjs +29 -0
- package/lib/esm/function-configuration.mjs +1 -0
- package/lib/esm/logger/common.mjs +23 -0
- package/lib/esm/logger/compat.mjs +25 -0
- package/lib/esm/logger/index.mjs +131 -0
- package/lib/esm/params/index.mjs +160 -0
- package/lib/esm/params/types.mjs +400 -0
- package/lib/esm/runtime/loader.mjs +132 -0
- package/lib/esm/runtime/manifest.mjs +134 -0
- package/lib/esm/types/global.d.mjs +1 -0
- package/lib/esm/v1/cloud-functions.mjs +206 -0
- package/lib/esm/v1/config.mjs +14 -0
- package/lib/esm/v1/function-builder.mjs +252 -0
- package/lib/esm/v1/function-configuration.mjs +72 -0
- package/lib/esm/v1/index.mjs +27 -0
- package/lib/esm/v1/providers/analytics.mjs +212 -0
- package/lib/esm/v1/providers/auth.mjs +156 -0
- package/lib/esm/v1/providers/database.mjs +243 -0
- package/lib/esm/v1/providers/firestore.mjs +131 -0
- package/lib/esm/v1/providers/https.mjs +82 -0
- package/lib/esm/v1/providers/pubsub.mjs +175 -0
- package/lib/esm/v1/providers/remoteConfig.mjs +64 -0
- package/lib/esm/v1/providers/storage.mjs +163 -0
- package/lib/esm/v1/providers/tasks.mjs +63 -0
- package/lib/esm/v1/providers/testLab.mjs +94 -0
- package/lib/esm/v2/core.mjs +4 -0
- package/lib/esm/v2/index.mjs +28 -0
- package/lib/esm/v2/options.mjs +102 -0
- package/lib/esm/v2/providers/alerts/alerts.mjs +85 -0
- package/lib/esm/v2/providers/alerts/appDistribution.mjs +75 -0
- package/lib/esm/v2/providers/alerts/billing.mjs +51 -0
- package/lib/esm/v2/providers/alerts/crashlytics.mjs +122 -0
- package/lib/esm/v2/providers/alerts/index.mjs +22 -0
- package/lib/esm/v2/providers/alerts/performance.mjs +66 -0
- package/lib/esm/v2/providers/database.mjs +197 -0
- package/lib/esm/v2/providers/dataconnect.mjs +130 -0
- package/lib/esm/v2/providers/eventarc.mjs +51 -0
- package/lib/esm/v2/providers/firestore.mjs +294 -0
- package/lib/esm/v2/providers/https.mjs +210 -0
- package/lib/esm/v2/providers/identity.mjs +103 -0
- package/lib/esm/v2/providers/pubsub.mjs +148 -0
- package/lib/esm/v2/providers/remoteConfig.mjs +52 -0
- package/lib/esm/v2/providers/scheduler.mjs +84 -0
- package/lib/esm/v2/providers/storage.mjs +155 -0
- package/lib/esm/v2/providers/tasks.mjs +65 -0
- package/lib/esm/v2/providers/testLab.mjs +53 -0
- package/lib/esm/v2/trace.mjs +20 -0
- package/lib/function-configuration.d.ts +0 -0
- package/lib/function-configuration.js +0 -0
- package/lib/logger/common.js +21 -41
- package/lib/logger/compat.js +18 -33
- package/lib/logger/index.js +119 -130
- package/lib/params/index.d.ts +4 -2
- package/lib/params/index.js +150 -144
- package/lib/params/types.js +389 -423
- package/lib/runtime/loader.js +114 -148
- package/lib/runtime/manifest.js +106 -126
- package/lib/types/global.d.js +0 -0
- package/lib/v1/cloud-functions.d.ts +2 -2
- package/lib/v1/cloud-functions.js +193 -241
- package/lib/v1/config.d.ts +4 -7
- package/lib/v1/config.js +13 -75
- package/lib/v1/function-builder.js +239 -368
- package/lib/v1/function-configuration.js +70 -63
- package/lib/v1/index.js +118 -73
- package/lib/v1/providers/analytics.js +188 -235
- package/lib/v1/providers/auth.d.ts +2 -1
- package/lib/v1/providers/auth.js +159 -164
- package/lib/v1/providers/database.js +237 -242
- package/lib/v1/providers/firestore.js +131 -130
- package/lib/v1/providers/https.d.ts +2 -1
- package/lib/v1/providers/https.js +79 -86
- package/lib/v1/providers/pubsub.js +175 -172
- package/lib/v1/providers/remoteConfig.js +64 -68
- package/lib/v1/providers/storage.js +161 -163
- package/lib/v1/providers/tasks.d.ts +1 -1
- package/lib/v1/providers/tasks.js +65 -80
- package/lib/v1/providers/testLab.js +94 -94
- package/lib/v2/core.d.ts +1 -1
- package/lib/v2/core.js +5 -32
- package/lib/v2/index.d.ts +6 -3
- package/lib/v2/index.js +123 -75
- package/lib/v2/options.js +88 -114
- package/lib/v2/providers/alerts/alerts.js +76 -95
- package/lib/v2/providers/alerts/appDistribution.js +73 -78
- package/lib/v2/providers/alerts/billing.js +49 -53
- package/lib/v2/providers/alerts/crashlytics.js +110 -102
- package/lib/v2/providers/alerts/index.js +56 -53
- package/lib/v2/providers/alerts/performance.js +64 -74
- package/lib/v2/providers/database.js +177 -180
- package/lib/v2/providers/dataconnect.d.ts +95 -0
- package/lib/v2/providers/dataconnect.js +137 -0
- package/lib/v2/providers/eventarc.js +55 -77
- package/lib/v2/providers/firestore.js +262 -260
- package/lib/v2/providers/https.d.ts +3 -2
- package/lib/v2/providers/https.js +210 -247
- package/lib/v2/providers/identity.d.ts +2 -1
- package/lib/v2/providers/identity.js +96 -105
- package/lib/v2/providers/pubsub.js +149 -167
- package/lib/v2/providers/remoteConfig.js +54 -63
- package/lib/v2/providers/scheduler.js +84 -96
- package/lib/v2/providers/storage.js +147 -162
- package/lib/v2/providers/tasks.d.ts +1 -1
- package/lib/v2/providers/tasks.js +68 -95
- package/lib/v2/providers/testLab.js +55 -64
- package/lib/v2/trace.js +18 -19
- package/package.json +290 -226
- package/protos/compiledFirestore.mjs +3512 -0
- package/protos/update.sh +28 -7
|
@@ -1,263 +1,258 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// SOFTWARE.
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.extractInstanceAndPath = exports.RefBuilder = exports._refWithOptions = exports.InstanceBuilder = exports._instanceWithOptions = exports.ref = exports.instance = exports.service = exports.provider = exports.DataSnapshot = void 0;
|
|
25
|
-
const app_1 = require("../../common/app");
|
|
26
|
-
const config_1 = require("../../common/config");
|
|
27
|
-
const database_1 = require("../../common/providers/database");
|
|
28
|
-
Object.defineProperty(exports, "DataSnapshot", { enumerable: true, get: function () { return database_1.DataSnapshot; } });
|
|
29
|
-
const path_1 = require("../../common/utilities/path");
|
|
30
|
-
const utils_1 = require("../../common/utilities/utils");
|
|
31
|
-
const cloud_functions_1 = require("../cloud-functions");
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_common_config = require('../../common/config.js');
|
|
3
|
+
const require_common_app = require('../../common/app.js');
|
|
4
|
+
const require_v1_cloud_functions = require('../cloud-functions.js');
|
|
5
|
+
const require_common_utilities_path = require('../../common/utilities/path.js');
|
|
6
|
+
const require_common_providers_database = require('../../common/providers/database.js');
|
|
7
|
+
const require_common_utilities_utils = require('../../common/utilities/utils.js');
|
|
8
|
+
|
|
9
|
+
//#region src/v1/providers/database.ts
|
|
10
|
+
var database_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
11
|
+
DataSnapshot: () => require_common_providers_database.DataSnapshot,
|
|
12
|
+
InstanceBuilder: () => InstanceBuilder,
|
|
13
|
+
RefBuilder: () => RefBuilder,
|
|
14
|
+
_instanceWithOptions: () => _instanceWithOptions,
|
|
15
|
+
_refWithOptions: () => _refWithOptions,
|
|
16
|
+
extractInstanceAndPath: () => extractInstanceAndPath,
|
|
17
|
+
instance: () => instance,
|
|
18
|
+
provider: () => provider,
|
|
19
|
+
ref: () => ref,
|
|
20
|
+
service: () => service
|
|
21
|
+
});
|
|
32
22
|
/** @internal */
|
|
33
|
-
|
|
23
|
+
const provider = "google.firebase.database";
|
|
34
24
|
/** @internal */
|
|
35
|
-
|
|
25
|
+
const service = "firebaseio.com";
|
|
36
26
|
const databaseURLRegex = new RegExp("^https://([^.]+).");
|
|
37
27
|
const emulatorDatabaseURLRegex = new RegExp("^http://.*ns=([^&]+)");
|
|
38
28
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function instance(instance) {
|
|
54
|
-
|
|
29
|
+
* Registers a function that triggers on events from a specific
|
|
30
|
+
* Firebase Realtime Database instance.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Use this method together with `ref` to specify the instance on which to
|
|
34
|
+
* watch for database events. For example: `firebase.database.instance('my-app-db-2').ref('/foo/bar')`
|
|
35
|
+
*
|
|
36
|
+
* Note that `functions.database.ref` used without `instance` watches the
|
|
37
|
+
* *default* instance for events.
|
|
38
|
+
*
|
|
39
|
+
* @param instance The instance name of the database instance
|
|
40
|
+
* to watch for write events.
|
|
41
|
+
* @returns Firebase Realtime Database instance builder interface.
|
|
42
|
+
*/
|
|
43
|
+
function instance(instance$1) {
|
|
44
|
+
return _instanceWithOptions(instance$1, {});
|
|
55
45
|
}
|
|
56
|
-
exports.instance = instance;
|
|
57
46
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
47
|
+
* Registers a function that triggers on Firebase Realtime Database write
|
|
48
|
+
* events.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* This method behaves very similarly to the method of the same name in the
|
|
52
|
+
* client and Admin Firebase SDKs. Any change to the Database that affects the
|
|
53
|
+
* data at or below the provided `path` will fire an event in Cloud Functions.
|
|
54
|
+
*
|
|
55
|
+
* There are three important differences between listening to a Realtime
|
|
56
|
+
* Database event in Cloud Functions and using the Realtime Database in the
|
|
57
|
+
* client and Admin SDKs:
|
|
58
|
+
*
|
|
59
|
+
* 1. Cloud Functions allows wildcards in the `path` name. Any `path` component
|
|
60
|
+
* in curly brackets (`{}`) is a wildcard that matches all strings. The value
|
|
61
|
+
* that matched a certain invocation of a Cloud Function is returned as part
|
|
62
|
+
* of the [`EventContext.params`](cloud_functions_eventcontext.html#params object. For
|
|
63
|
+
* example, `ref("messages/{messageId}")` matches changes at
|
|
64
|
+
* `/messages/message1` or `/messages/message2`, resulting in
|
|
65
|
+
* `event.params.messageId` being set to `"message1"` or `"message2"`,
|
|
66
|
+
* respectively.
|
|
67
|
+
*
|
|
68
|
+
* 2. Cloud Functions do not fire an event for data that already existed before
|
|
69
|
+
* the Cloud Function was deployed.
|
|
70
|
+
*
|
|
71
|
+
* 3. Cloud Function events have access to more information, including a
|
|
72
|
+
* snapshot of the previous event data and information about the user who
|
|
73
|
+
* triggered the Cloud Function.
|
|
74
|
+
*
|
|
75
|
+
* @param path The path within the Database to watch for write events.
|
|
76
|
+
* @returns Firebase Realtime Database builder interface.
|
|
77
|
+
*/
|
|
89
78
|
function ref(path) {
|
|
90
|
-
|
|
79
|
+
return _refWithOptions(path, {});
|
|
91
80
|
}
|
|
92
|
-
exports.ref = ref;
|
|
93
81
|
/** @internal */
|
|
94
|
-
function _instanceWithOptions(instance, options) {
|
|
95
|
-
|
|
82
|
+
function _instanceWithOptions(instance$1, options) {
|
|
83
|
+
return new InstanceBuilder(instance$1, options);
|
|
96
84
|
}
|
|
97
|
-
exports._instanceWithOptions = _instanceWithOptions;
|
|
98
85
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
exports.InstanceBuilder = InstanceBuilder;
|
|
86
|
+
* The Firebase Realtime Database instance builder interface.
|
|
87
|
+
*
|
|
88
|
+
* Access via [`database.instance()`](providers_database_.html#instance).
|
|
89
|
+
*/
|
|
90
|
+
var InstanceBuilder = class {
|
|
91
|
+
constructor(instance$1, options) {
|
|
92
|
+
this.instance = instance$1;
|
|
93
|
+
this.options = options;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @returns Firebase Realtime Database reference builder interface.
|
|
97
|
+
*/
|
|
98
|
+
ref(path) {
|
|
99
|
+
const normalized = require_common_utilities_path.normalizePath(path);
|
|
100
|
+
return new RefBuilder(() => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
117
103
|
/** @internal */
|
|
118
104
|
function _refWithOptions(path, options) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
return `projects/_/instances/${instance}/refs/${normalized}`;
|
|
143
|
-
};
|
|
144
|
-
return new RefBuilder(resourceGetter, options);
|
|
105
|
+
const resourceGetter = () => {
|
|
106
|
+
const normalized = require_common_utilities_path.normalizePath(path);
|
|
107
|
+
const databaseURL = require_common_config.firebaseConfig().databaseURL;
|
|
108
|
+
if (!databaseURL) {
|
|
109
|
+
throw new Error("Missing expected firebase config value databaseURL, " + "config is actually" + JSON.stringify(require_common_config.firebaseConfig()) + "\n If you are unit testing, please set process.env.FIREBASE_CONFIG");
|
|
110
|
+
}
|
|
111
|
+
let instance$1;
|
|
112
|
+
const prodMatch = databaseURL.match(databaseURLRegex);
|
|
113
|
+
if (prodMatch) {
|
|
114
|
+
instance$1 = prodMatch[1];
|
|
115
|
+
} else {
|
|
116
|
+
const emulatorMatch = databaseURL.match(emulatorDatabaseURLRegex);
|
|
117
|
+
if (emulatorMatch) {
|
|
118
|
+
instance$1 = emulatorMatch[1];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!instance$1) {
|
|
122
|
+
throw new Error("Invalid value for config firebase.databaseURL: " + databaseURL);
|
|
123
|
+
}
|
|
124
|
+
return `projects/_/instances/${instance$1}/refs/${normalized}`;
|
|
125
|
+
};
|
|
126
|
+
return new RefBuilder(resourceGetter, options);
|
|
145
127
|
}
|
|
146
|
-
exports._refWithOptions = _refWithOptions;
|
|
147
128
|
/**
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
exports.RefBuilder = RefBuilder;
|
|
129
|
+
* The Firebase Realtime Database reference builder interface.
|
|
130
|
+
*
|
|
131
|
+
* Access via [`functions.database.ref()`](functions.database#.ref).
|
|
132
|
+
*/
|
|
133
|
+
var RefBuilder = class {
|
|
134
|
+
constructor(triggerResource, options) {
|
|
135
|
+
this.triggerResource = triggerResource;
|
|
136
|
+
this.options = options;
|
|
137
|
+
this.changeConstructor = (raw) => {
|
|
138
|
+
const [dbInstance, path] = extractInstanceAndPath(raw.context.resource.name, raw.context.domain);
|
|
139
|
+
const before = new require_common_providers_database.DataSnapshot(raw.data.data, path, require_common_app.getApp(), dbInstance);
|
|
140
|
+
const after = new require_common_providers_database.DataSnapshot(require_common_utilities_utils.applyChange(raw.data.data, raw.data.delta), path, require_common_app.getApp(), dbInstance);
|
|
141
|
+
return {
|
|
142
|
+
before,
|
|
143
|
+
after
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Event handler that fires every time a Firebase Realtime Database write
|
|
149
|
+
* of any kind (creation, update, or delete) occurs.
|
|
150
|
+
*
|
|
151
|
+
* @param handler Event handler that runs every time a Firebase Realtime Database
|
|
152
|
+
* write occurs.
|
|
153
|
+
* @returns A function that you can export and deploy.
|
|
154
|
+
*/
|
|
155
|
+
onWrite(handler) {
|
|
156
|
+
return this.onOperation(handler, "ref.write", this.changeConstructor);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Event handler that fires every time data is updated in
|
|
160
|
+
* Firebase Realtime Database.
|
|
161
|
+
*
|
|
162
|
+
* @param handler Event handler which is run every time a Firebase Realtime Database
|
|
163
|
+
* write occurs.
|
|
164
|
+
* @returns A function which you can export and deploy.
|
|
165
|
+
*/
|
|
166
|
+
onUpdate(handler) {
|
|
167
|
+
return this.onOperation(handler, "ref.update", this.changeConstructor);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Event handler that fires every time new data is created in
|
|
171
|
+
* Firebase Realtime Database.
|
|
172
|
+
*
|
|
173
|
+
* @param handler Event handler that runs every time new data is created in
|
|
174
|
+
* Firebase Realtime Database.
|
|
175
|
+
* @returns A function that you can export and deploy.
|
|
176
|
+
*/
|
|
177
|
+
onCreate(handler) {
|
|
178
|
+
const dataConstructor = (raw) => {
|
|
179
|
+
const [dbInstance, path] = extractInstanceAndPath(raw.context.resource.name, raw.context.domain);
|
|
180
|
+
return new require_common_providers_database.DataSnapshot(raw.data.delta, path, require_common_app.getApp(), dbInstance);
|
|
181
|
+
};
|
|
182
|
+
return this.onOperation(handler, "ref.create", dataConstructor);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Event handler that fires every time data is deleted from
|
|
186
|
+
* Firebase Realtime Database.
|
|
187
|
+
*
|
|
188
|
+
* @param handler Event handler that runs every time data is deleted from
|
|
189
|
+
* Firebase Realtime Database.
|
|
190
|
+
* @returns A function that you can export and deploy.
|
|
191
|
+
*/
|
|
192
|
+
onDelete(handler) {
|
|
193
|
+
const dataConstructor = (raw) => {
|
|
194
|
+
const [dbInstance, path] = extractInstanceAndPath(raw.context.resource.name, raw.context.domain);
|
|
195
|
+
return new require_common_providers_database.DataSnapshot(raw.data.data, path, require_common_app.getApp(), dbInstance);
|
|
196
|
+
};
|
|
197
|
+
return this.onOperation(handler, "ref.delete", dataConstructor);
|
|
198
|
+
}
|
|
199
|
+
onOperation(handler, eventType, dataConstructor) {
|
|
200
|
+
return require_v1_cloud_functions.makeCloudFunction({
|
|
201
|
+
handler,
|
|
202
|
+
provider,
|
|
203
|
+
service,
|
|
204
|
+
eventType,
|
|
205
|
+
legacyEventType: `providers/${provider}/eventTypes/${eventType}`,
|
|
206
|
+
triggerResource: this.triggerResource,
|
|
207
|
+
dataConstructor,
|
|
208
|
+
options: this.options
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
};
|
|
232
212
|
const resourceRegex = /^projects\/([^/]+)\/instances\/([a-zA-Z0-9-]+)\/refs(\/.+)?/;
|
|
233
213
|
/**
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
214
|
+
* Utility function to extract database reference from resource string
|
|
215
|
+
*
|
|
216
|
+
* @param optional database domain override for the original of the source database.
|
|
217
|
+
* It defaults to `firebaseio.com`.
|
|
218
|
+
* Multi-region RTDB will be served from different domains.
|
|
219
|
+
* Since region is not part of the resource name, it is provided through context.
|
|
220
|
+
*
|
|
221
|
+
* @internal
|
|
222
|
+
*/
|
|
243
223
|
function extractInstanceAndPath(resource, domain = "firebaseio.com") {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return [dbInstance, path];
|
|
261
|
-
}
|
|
224
|
+
const match = resource.match(new RegExp(resourceRegex));
|
|
225
|
+
if (!match) {
|
|
226
|
+
throw new Error(`Unexpected resource string for Firebase Realtime Database event: ${resource}. ` + "Expected string in the format of \"projects/_/instances/{firebaseioSubdomain}/refs/{ref=**}\"");
|
|
227
|
+
}
|
|
228
|
+
const [, project, dbInstanceName, path] = match;
|
|
229
|
+
if (project !== "_") {
|
|
230
|
+
throw new Error(`Expect project to be '_' in a Firebase Realtime Database event`);
|
|
231
|
+
}
|
|
232
|
+
const emuHost = process.env.FIREBASE_DATABASE_EMULATOR_HOST;
|
|
233
|
+
if (emuHost) {
|
|
234
|
+
const dbInstance = `http://${emuHost}/?ns=${dbInstanceName}`;
|
|
235
|
+
return [dbInstance, path];
|
|
236
|
+
} else {
|
|
237
|
+
const dbInstance = "https://" + dbInstanceName + "." + domain;
|
|
238
|
+
return [dbInstance, path];
|
|
239
|
+
}
|
|
262
240
|
}
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
exports.DataSnapshot = require_common_providers_database.DataSnapshot;
|
|
244
|
+
exports.InstanceBuilder = InstanceBuilder;
|
|
245
|
+
exports.RefBuilder = RefBuilder;
|
|
246
|
+
exports._instanceWithOptions = _instanceWithOptions;
|
|
247
|
+
exports._refWithOptions = _refWithOptions;
|
|
248
|
+
Object.defineProperty(exports, 'database_exports', {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
get: function () {
|
|
251
|
+
return database_exports;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
263
254
|
exports.extractInstanceAndPath = extractInstanceAndPath;
|
|
255
|
+
exports.instance = instance;
|
|
256
|
+
exports.provider = provider;
|
|
257
|
+
exports.ref = ref;
|
|
258
|
+
exports.service = service;
|