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