firebase-functions 6.6.0 → 7.0.0-rc.1

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 +321 -88
  155. package/protos/compiledFirestore.mjs +3512 -0
  156. package/protos/update.sh +28 -7
@@ -1,219 +1,216 @@
1
- "use strict";
2
- // The MIT License (MIT)
3
- //
4
- // Copyright (c) 2022 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.onOperation = exports.onChangedOperation = exports.makeEndpoint = exports.makeParams = exports.getOpts = exports.onValueDeleted = exports.onValueUpdated = exports.onValueCreated = exports.onValueWritten = exports.deletedEventType = exports.updatedEventType = exports.createdEventType = exports.writtenEventType = exports.DataSnapshot = void 0;
25
- const app_1 = require("../../common/app");
26
- const database_1 = require("../../common/providers/database");
27
- Object.defineProperty(exports, "DataSnapshot", { enumerable: true, get: function () { return database_1.DataSnapshot; } });
28
- const path_1 = require("../../common/utilities/path");
29
- const path_pattern_1 = require("../../common/utilities/path-pattern");
30
- const utils_1 = require("../../common/utilities/utils");
31
- const manifest_1 = require("../../runtime/manifest");
32
- const trace_1 = require("../trace");
33
- const options = require("../options");
34
- const onInit_1 = require("../../common/onInit");
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
2
+ const require_runtime_manifest = require('../../runtime/manifest.js');
3
+ const require_common_app = require('../../common/app.js');
4
+ const require_common_onInit = require('../../common/onInit.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
+ const require_v2_trace = require('../trace.js');
9
+ const require_v2_options = require('../options.js');
10
+ const require_common_utilities_path_pattern = require('../../common/utilities/path-pattern.js');
11
+
12
+ //#region src/v2/providers/database.ts
13
+ var database_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
14
+ DataSnapshot: () => require_common_providers_database.DataSnapshot,
15
+ createdEventType: () => createdEventType,
16
+ deletedEventType: () => deletedEventType,
17
+ getOpts: () => getOpts,
18
+ makeEndpoint: () => makeEndpoint,
19
+ makeParams: () => makeParams,
20
+ onChangedOperation: () => onChangedOperation,
21
+ onOperation: () => onOperation,
22
+ onValueCreated: () => onValueCreated,
23
+ onValueDeleted: () => onValueDeleted,
24
+ onValueUpdated: () => onValueUpdated,
25
+ onValueWritten: () => onValueWritten,
26
+ updatedEventType: () => updatedEventType,
27
+ writtenEventType: () => writtenEventType
28
+ });
35
29
  /** @internal */
36
- exports.writtenEventType = "google.firebase.database.ref.v1.written";
30
+ const writtenEventType = "google.firebase.database.ref.v1.written";
37
31
  /** @internal */
38
- exports.createdEventType = "google.firebase.database.ref.v1.created";
32
+ const createdEventType = "google.firebase.database.ref.v1.created";
39
33
  /** @internal */
40
- exports.updatedEventType = "google.firebase.database.ref.v1.updated";
34
+ const updatedEventType = "google.firebase.database.ref.v1.updated";
41
35
  /** @internal */
42
- exports.deletedEventType = "google.firebase.database.ref.v1.deleted";
36
+ const deletedEventType = "google.firebase.database.ref.v1.deleted";
43
37
  /**
44
- * Event handler which triggers when data is created, updated, or deleted in Realtime Database.
45
- *
46
- * @param referenceOrOpts - Options or a string reference.
47
- * @param handler - Event handler which is run every time a Realtime Database create, update, or delete occurs.
48
- */
38
+ * Event handler which triggers when data is created, updated, or deleted in Realtime Database.
39
+ *
40
+ * @param referenceOrOpts - Options or a string reference.
41
+ * @param handler - Event handler which is run every time a Realtime Database create, update, or delete occurs.
42
+ */
49
43
  function onValueWritten(referenceOrOpts, handler) {
50
- return onChangedOperation(exports.writtenEventType, referenceOrOpts, handler);
44
+ return onChangedOperation(writtenEventType, referenceOrOpts, handler);
51
45
  }
52
- exports.onValueWritten = onValueWritten;
53
46
  /**
54
- * Event handler which triggers when data is created in Realtime Database.
55
- *
56
- * @param referenceOrOpts - Options or a string reference.
57
- * @param handler - Event handler which is run every time a Realtime Database create occurs.
58
- */
47
+ * Event handler which triggers when data is created in Realtime Database.
48
+ *
49
+ * @param referenceOrOpts - Options or a string reference.
50
+ * @param handler - Event handler which is run every time a Realtime Database create occurs.
51
+ */
59
52
  function onValueCreated(referenceOrOpts, handler) {
60
- return onOperation(exports.createdEventType, referenceOrOpts, handler);
53
+ return onOperation(createdEventType, referenceOrOpts, handler);
61
54
  }
62
- exports.onValueCreated = onValueCreated;
63
55
  /**
64
- * Event handler which triggers when data is updated in Realtime Database.
65
- *
66
- * @param referenceOrOpts - Options or a string reference.
67
- * @param handler - Event handler which is run every time a Realtime Database update occurs.
68
- */
56
+ * Event handler which triggers when data is updated in Realtime Database.
57
+ *
58
+ * @param referenceOrOpts - Options or a string reference.
59
+ * @param handler - Event handler which is run every time a Realtime Database update occurs.
60
+ */
69
61
  function onValueUpdated(referenceOrOpts, handler) {
70
- return onChangedOperation(exports.updatedEventType, referenceOrOpts, handler);
62
+ return onChangedOperation(updatedEventType, referenceOrOpts, handler);
71
63
  }
72
- exports.onValueUpdated = onValueUpdated;
73
64
  /**
74
- * Event handler which triggers when data is deleted in Realtime Database.
75
- *
76
- * @param referenceOrOpts - Options or a string reference.
77
- * @param handler - Event handler which is run every time a Realtime Database deletion occurs.
78
- */
65
+ * Event handler which triggers when data is deleted in Realtime Database.
66
+ *
67
+ * @param referenceOrOpts - Options or a string reference.
68
+ * @param handler - Event handler which is run every time a Realtime Database deletion occurs.
69
+ */
79
70
  function onValueDeleted(referenceOrOpts, handler) {
80
- // TODO - need to use event.data.delta
81
- return onOperation(exports.deletedEventType, referenceOrOpts, handler);
71
+ return onOperation(deletedEventType, referenceOrOpts, handler);
82
72
  }
83
- exports.onValueDeleted = onValueDeleted;
84
73
  /** @internal */
85
74
  function getOpts(referenceOrOpts) {
86
- let path;
87
- let instance;
88
- let opts;
89
- if (typeof referenceOrOpts === "string") {
90
- path = (0, path_1.normalizePath)(referenceOrOpts);
91
- instance = "*";
92
- opts = {};
93
- }
94
- else {
95
- path = (0, path_1.normalizePath)(referenceOrOpts.ref);
96
- instance = referenceOrOpts.instance || "*";
97
- opts = { ...referenceOrOpts };
98
- delete opts.ref;
99
- delete opts.instance;
100
- }
101
- return {
102
- path,
103
- instance,
104
- opts,
105
- };
75
+ let path;
76
+ let instance;
77
+ let opts;
78
+ if (typeof referenceOrOpts === "string") {
79
+ path = require_common_utilities_path.normalizePath(referenceOrOpts);
80
+ instance = "*";
81
+ opts = {};
82
+ } else {
83
+ path = require_common_utilities_path.normalizePath(referenceOrOpts.ref);
84
+ instance = referenceOrOpts.instance || "*";
85
+ opts = { ...referenceOrOpts };
86
+ delete opts.ref;
87
+ delete opts.instance;
88
+ }
89
+ return {
90
+ path,
91
+ instance,
92
+ opts
93
+ };
106
94
  }
107
- exports.getOpts = getOpts;
108
95
  /** @internal */
109
96
  function makeParams(event, path, instance) {
110
- return {
111
- ...path.extractMatches(event.ref),
112
- ...instance.extractMatches(event.instance),
113
- };
97
+ return {
98
+ ...path.extractMatches(event.ref),
99
+ ...instance.extractMatches(event.instance)
100
+ };
114
101
  }
115
- exports.makeParams = makeParams;
116
102
  /** @hidden */
117
103
  function makeDatabaseEvent(event, data, instance, params) {
118
- const snapshot = new database_1.DataSnapshot(data, event.ref, (0, app_1.getApp)(), instance);
119
- const databaseEvent = {
120
- ...event,
121
- firebaseDatabaseHost: event.firebasedatabasehost,
122
- data: snapshot,
123
- params,
124
- };
125
- delete databaseEvent.firebasedatabasehost;
126
- return databaseEvent;
104
+ const snapshot = new require_common_providers_database.DataSnapshot(data, event.ref, require_common_app.getApp(), instance);
105
+ const databaseEvent = {
106
+ ...event,
107
+ firebaseDatabaseHost: event.firebasedatabasehost,
108
+ data: snapshot,
109
+ params
110
+ };
111
+ delete databaseEvent.firebasedatabasehost;
112
+ return databaseEvent;
127
113
  }
128
114
  /** @hidden */
129
115
  function makeChangedDatabaseEvent(event, instance, params) {
130
- const before = new database_1.DataSnapshot(event.data.data, event.ref, (0, app_1.getApp)(), instance);
131
- const after = new database_1.DataSnapshot((0, utils_1.applyChange)(event.data.data, event.data.delta), event.ref, (0, app_1.getApp)(), instance);
132
- const databaseEvent = {
133
- ...event,
134
- firebaseDatabaseHost: event.firebasedatabasehost,
135
- data: {
136
- before,
137
- after,
138
- },
139
- params,
140
- };
141
- delete databaseEvent.firebasedatabasehost;
142
- return databaseEvent;
116
+ const before = new require_common_providers_database.DataSnapshot(event.data.data, event.ref, require_common_app.getApp(), instance);
117
+ const after = new require_common_providers_database.DataSnapshot(require_common_utilities_utils.applyChange(event.data.data, event.data.delta), event.ref, require_common_app.getApp(), instance);
118
+ const databaseEvent = {
119
+ ...event,
120
+ firebaseDatabaseHost: event.firebasedatabasehost,
121
+ data: {
122
+ before,
123
+ after
124
+ },
125
+ params
126
+ };
127
+ delete databaseEvent.firebasedatabasehost;
128
+ return databaseEvent;
143
129
  }
144
130
  /** @internal */
145
131
  function makeEndpoint(eventType, opts, path, instance) {
146
- var _a;
147
- const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
148
- const specificOpts = options.optionsToEndpoint(opts);
149
- const eventFilters = {};
150
- const eventFilterPathPatterns = {
151
- // Note: Eventarc always treats ref as a path pattern
152
- ref: path.getValue(),
153
- };
154
- instance.hasWildcards()
155
- ? (eventFilterPathPatterns.instance = instance.getValue())
156
- : (eventFilters.instance = instance.getValue());
157
- return {
158
- ...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
159
- platform: "gcfv2",
160
- ...baseOpts,
161
- ...specificOpts,
162
- labels: {
163
- ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
164
- ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
165
- },
166
- eventTrigger: {
167
- eventType,
168
- eventFilters,
169
- eventFilterPathPatterns,
170
- retry: (_a = opts.retry) !== null && _a !== void 0 ? _a : false,
171
- },
172
- };
132
+ const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
133
+ const specificOpts = require_v2_options.optionsToEndpoint(opts);
134
+ const eventFilters = {};
135
+ const eventFilterPathPatterns = { ref: path.getValue() };
136
+ if (instance.hasWildcards()) {
137
+ eventFilterPathPatterns.instance = instance.getValue();
138
+ } else {
139
+ eventFilters.instance = instance.getValue();
140
+ }
141
+ return {
142
+ ...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
143
+ platform: "gcfv2",
144
+ ...baseOpts,
145
+ ...specificOpts,
146
+ labels: {
147
+ ...baseOpts?.labels,
148
+ ...specificOpts?.labels
149
+ },
150
+ eventTrigger: {
151
+ eventType,
152
+ eventFilters,
153
+ eventFilterPathPatterns,
154
+ retry: opts.retry ?? false
155
+ }
156
+ };
173
157
  }
174
- exports.makeEndpoint = makeEndpoint;
175
158
  /** @internal */
176
159
  function onChangedOperation(eventType, referenceOrOpts, handler) {
177
- const { path, instance, opts } = getOpts(referenceOrOpts);
178
- const pathPattern = new path_pattern_1.PathPattern(path);
179
- const instancePattern = new path_pattern_1.PathPattern(instance);
180
- // wrap the handler
181
- const func = (raw) => {
182
- const event = raw;
183
- const instanceUrl = getInstance(event);
184
- const params = makeParams(event, pathPattern, instancePattern);
185
- const databaseEvent = makeChangedDatabaseEvent(event, instanceUrl, params);
186
- // Intentionally put init in the context of traces in case there is something
187
- // expensive to observe.
188
- return (0, trace_1.wrapTraceContext)((0, onInit_1.withInit)(handler))(databaseEvent);
189
- };
190
- func.run = handler;
191
- func.__endpoint = makeEndpoint(eventType, opts, pathPattern, instancePattern);
192
- return func;
160
+ const { path, instance, opts } = getOpts(referenceOrOpts);
161
+ const pathPattern = new require_common_utilities_path_pattern.PathPattern(path);
162
+ const instancePattern = new require_common_utilities_path_pattern.PathPattern(instance);
163
+ const func = (raw) => {
164
+ const event = raw;
165
+ const instanceUrl = getInstance(event);
166
+ const params = makeParams(event, pathPattern, instancePattern);
167
+ const databaseEvent = makeChangedDatabaseEvent(event, instanceUrl, params);
168
+ return require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler))(databaseEvent);
169
+ };
170
+ func.run = handler;
171
+ func.__endpoint = makeEndpoint(eventType, opts, pathPattern, instancePattern);
172
+ return func;
193
173
  }
194
- exports.onChangedOperation = onChangedOperation;
195
174
  /** @internal */
196
175
  function onOperation(eventType, referenceOrOpts, handler) {
197
- const { path, instance, opts } = getOpts(referenceOrOpts);
198
- const pathPattern = new path_pattern_1.PathPattern(path);
199
- const instancePattern = new path_pattern_1.PathPattern(instance);
200
- // wrap the handler
201
- const func = (raw) => {
202
- const event = raw;
203
- const instanceUrl = getInstance(event);
204
- const params = makeParams(event, pathPattern, instancePattern);
205
- const data = eventType === exports.deletedEventType ? event.data.data : event.data.delta;
206
- const databaseEvent = makeDatabaseEvent(event, data, instanceUrl, params);
207
- return (0, trace_1.wrapTraceContext)((0, onInit_1.withInit)(handler))(databaseEvent);
208
- };
209
- func.run = handler;
210
- func.__endpoint = makeEndpoint(eventType, opts, pathPattern, instancePattern);
211
- return func;
176
+ const { path, instance, opts } = getOpts(referenceOrOpts);
177
+ const pathPattern = new require_common_utilities_path_pattern.PathPattern(path);
178
+ const instancePattern = new require_common_utilities_path_pattern.PathPattern(instance);
179
+ const func = (raw) => {
180
+ const event = raw;
181
+ const instanceUrl = getInstance(event);
182
+ const params = makeParams(event, pathPattern, instancePattern);
183
+ const data = eventType === deletedEventType ? event.data.data : event.data.delta;
184
+ const databaseEvent = makeDatabaseEvent(event, data, instanceUrl, params);
185
+ return require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler))(databaseEvent);
186
+ };
187
+ func.run = handler;
188
+ func.__endpoint = makeEndpoint(eventType, opts, pathPattern, instancePattern);
189
+ return func;
212
190
  }
213
- exports.onOperation = onOperation;
214
191
  function getInstance(event) {
215
- const emuHost = process.env.FIREBASE_DATABASE_EMULATOR_HOST;
216
- return emuHost
217
- ? `http://${emuHost}/?ns=${event.instance}`
218
- : `https://${event.instance}.${event.firebasedatabasehost}`;
192
+ const emuHost = process.env.FIREBASE_DATABASE_EMULATOR_HOST;
193
+ return emuHost ? `http://${emuHost}/?ns=${event.instance}` : `https://${event.instance}.${event.firebasedatabasehost}`;
219
194
  }
195
+
196
+ //#endregion
197
+ exports.DataSnapshot = require_common_providers_database.DataSnapshot;
198
+ exports.createdEventType = createdEventType;
199
+ Object.defineProperty(exports, 'database_exports', {
200
+ enumerable: true,
201
+ get: function () {
202
+ return database_exports;
203
+ }
204
+ });
205
+ exports.deletedEventType = deletedEventType;
206
+ exports.getOpts = getOpts;
207
+ exports.makeEndpoint = makeEndpoint;
208
+ exports.makeParams = makeParams;
209
+ exports.onChangedOperation = onChangedOperation;
210
+ exports.onOperation = onOperation;
211
+ exports.onValueCreated = onValueCreated;
212
+ exports.onValueDeleted = onValueDeleted;
213
+ exports.onValueUpdated = onValueUpdated;
214
+ exports.onValueWritten = onValueWritten;
215
+ exports.updatedEventType = updatedEventType;
216
+ exports.writtenEventType = writtenEventType;
@@ -0,0 +1,95 @@
1
+ import { CloudEvent, CloudFunction } from "../core";
2
+ import { ParamsOf, VarName } from "../../common/params";
3
+ import { EventHandlerOptions, SupportedRegion } from "../options";
4
+ import { Expression } from "../../params";
5
+ import { ResetValue } from "../../common/options";
6
+ /** @hidden */
7
+ export interface SourceLocation {
8
+ line: number;
9
+ column: number;
10
+ }
11
+ /** @hidden */
12
+ export interface GraphqlErrorExtensions {
13
+ file: string;
14
+ code: string;
15
+ debugDetails: string;
16
+ }
17
+ /** @hidden */
18
+ export interface GraphqlError {
19
+ message: string;
20
+ locations: Array<SourceLocation>;
21
+ path: Array<string>;
22
+ extensions: GraphqlErrorExtensions;
23
+ }
24
+ /** @hidden */
25
+ export interface RawMutation<V, R> {
26
+ data: R;
27
+ variables: V;
28
+ errors: Array<GraphqlError>;
29
+ }
30
+ /** @hidden */
31
+ export interface MutationEventData<V, R> {
32
+ ["@type"]: "type.googleapis.com/google.events.firebase.dataconnect.v1.MutationEventData";
33
+ payload: RawMutation<V, R>;
34
+ }
35
+ /** @hidden */
36
+ export interface RawDataConnectEvent<T> extends CloudEvent<T> {
37
+ project: string;
38
+ location: string;
39
+ service: string;
40
+ schema: string;
41
+ connector: string;
42
+ operation: string;
43
+ authtype: AuthType;
44
+ authid?: string;
45
+ }
46
+ /**
47
+ * AuthType defines the possible values for the authType field in a Firebase Data Connect event.
48
+ * - app_user: an end user of an application..
49
+ * - admin: an admin user of an application. In the context of impersonate endpoints used by the admin SDK, the impersonator.
50
+ * - unknown: a general type to capture all other principals not captured in the other auth types.
51
+ */
52
+ export type AuthType = "app_user" | "admin" | "unknown";
53
+ /** OperationOptions extend EventHandlerOptions with a provided service, connector, and operation. */
54
+ export interface OperationOptions<Service extends string = string, Connector extends string = string, Operation extends string = string> extends EventHandlerOptions {
55
+ /** Firebase Data Connect service ID */
56
+ service?: Service;
57
+ /** Firebase Data Connect connector ID */
58
+ connector?: Connector;
59
+ /** Name of the operation */
60
+ operation?: Operation;
61
+ /**
62
+ * Region where functions should be deployed. Defaults to us-central1.
63
+ */
64
+ region?: SupportedRegion | string | Expression<string> | ResetValue;
65
+ }
66
+ export type DataConnectParams<PathPatternOrOptions extends string | OperationOptions> = PathPatternOrOptions extends string ? ParamsOf<PathPatternOrOptions> : PathPatternOrOptions extends OperationOptions<infer Service extends string, infer Connector extends string, infer Operation extends string> ? Record<VarName<Service> | VarName<Connector> | VarName<Operation>, string> : never;
67
+ export interface DataConnectEvent<T, Params extends Record<never, string>> extends CloudEvent<T> {
68
+ /** The location of the Firebase Data Connect instance */
69
+ location: string;
70
+ /** The project identifier */
71
+ project: string;
72
+ /**
73
+ * An object containing the values of the path patterns.
74
+ * Only named capture groups will be populated - {key}, {key=*}, {key=**}.
75
+ */
76
+ params: Params;
77
+ /** The type of principal that triggered the event */
78
+ authType: AuthType;
79
+ /** The unique identifier for the principal */
80
+ authId?: string;
81
+ }
82
+ /**
83
+ * Event handler that triggers when a mutation is executed in Firebase Data Connect.
84
+ *
85
+ * @param mutation - The mutation path to trigger on.
86
+ * @param handler - Event handler which is run every time a mutation is executed.
87
+ */
88
+ export declare function onMutationExecuted<Mutation extends string, Variables = unknown, ResponseData = unknown>(mutation: Mutation, handler: (event: DataConnectEvent<MutationEventData<Variables, ResponseData>, DataConnectParams<Mutation>>) => unknown | Promise<unknown>): CloudFunction<DataConnectEvent<MutationEventData<Variables, ResponseData>, DataConnectParams<Mutation>>>;
89
+ /**
90
+ * Event handler that triggers when a mutation is executed in Firebase Data Connect.
91
+ *
92
+ * @param opts - Options that can be set on an individual event-handling function.
93
+ * @param handler - Event handler which is run every time a mutation is executed.
94
+ */
95
+ export declare function onMutationExecuted<Options extends OperationOptions, Variables = unknown, ResponseData = unknown>(opts: Options, handler: (event: DataConnectEvent<MutationEventData<Variables, ResponseData>, DataConnectParams<Options>>) => unknown | Promise<unknown>): CloudFunction<DataConnectEvent<MutationEventData<Variables, ResponseData>, DataConnectParams<Options>>>;
@@ -0,0 +1,137 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
2
+ const require_runtime_manifest = require('../../runtime/manifest.js');
3
+ const require_common_onInit = require('../../common/onInit.js');
4
+ const require_common_utilities_path = require('../../common/utilities/path.js');
5
+ const require_v2_trace = require('../trace.js');
6
+ const require_v2_options = require('../options.js');
7
+ const require_common_utilities_path_pattern = require('../../common/utilities/path-pattern.js');
8
+
9
+ //#region src/v2/providers/dataconnect.ts
10
+ var dataconnect_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
11
+ mutationExecutedEventType: () => mutationExecutedEventType,
12
+ onMutationExecuted: () => onMutationExecuted
13
+ });
14
+ /** @internal */
15
+ const mutationExecutedEventType = "google.firebase.dataconnect.connector.v1.mutationExecuted";
16
+ /**
17
+ * Event handler that triggers when a mutation is executed in Firebase Data Connect.
18
+ *
19
+ * @param mutationOrOpts - Options or string mutation path.
20
+ * @param handler - Event handler which is run every time a mutation is executed.
21
+ */
22
+ function onMutationExecuted(mutationOrOpts, handler) {
23
+ return onOperation(mutationExecutedEventType, mutationOrOpts, handler);
24
+ }
25
+ function getOpts(mutationOrOpts) {
26
+ const operationRegex = new RegExp("services/([^/]+)/connectors/([^/]*)/operations/([^/]+)");
27
+ let service;
28
+ let connector;
29
+ let operation;
30
+ let opts;
31
+ if (typeof mutationOrOpts === "string") {
32
+ const path = require_common_utilities_path.normalizePath(mutationOrOpts);
33
+ const match = path.match(operationRegex);
34
+ if (!match) {
35
+ throw new Error(`Invalid operation path: ${path}`);
36
+ }
37
+ service = match[1];
38
+ connector = match[2];
39
+ operation = match[3];
40
+ opts = {};
41
+ } else {
42
+ service = mutationOrOpts.service;
43
+ connector = mutationOrOpts.connector;
44
+ operation = mutationOrOpts.operation;
45
+ opts = { ...mutationOrOpts };
46
+ delete opts.service;
47
+ delete opts.connector;
48
+ delete opts.operation;
49
+ }
50
+ return {
51
+ service,
52
+ connector,
53
+ operation,
54
+ opts
55
+ };
56
+ }
57
+ function makeEndpoint(eventType, opts, service, connector, operation) {
58
+ const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
59
+ const specificOpts = require_v2_options.optionsToEndpoint(opts);
60
+ const eventFilters = {};
61
+ const eventFilterPathPatterns = {};
62
+ if (service) {
63
+ if (service.hasWildcards()) {
64
+ eventFilterPathPatterns.service = service.getValue();
65
+ } else {
66
+ eventFilters.service = service.getValue();
67
+ }
68
+ }
69
+ if (connector) {
70
+ if (connector.hasWildcards()) {
71
+ eventFilterPathPatterns.connector = connector.getValue();
72
+ } else {
73
+ eventFilters.connector = connector.getValue();
74
+ }
75
+ }
76
+ if (operation) {
77
+ if (operation.hasWildcards()) {
78
+ eventFilterPathPatterns.operation = operation.getValue();
79
+ } else {
80
+ eventFilters.operation = operation.getValue();
81
+ }
82
+ }
83
+ return {
84
+ ...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
85
+ platform: "gcfv2",
86
+ ...baseOpts,
87
+ ...specificOpts,
88
+ labels: {
89
+ ...baseOpts?.labels,
90
+ ...specificOpts?.labels
91
+ },
92
+ eventTrigger: {
93
+ eventType,
94
+ eventFilters,
95
+ eventFilterPathPatterns,
96
+ retry: opts.retry ?? false
97
+ }
98
+ };
99
+ }
100
+ function makeParams(event, service, connector, operation) {
101
+ return {
102
+ ...service?.extractMatches(event.service),
103
+ ...connector?.extractMatches(event.connector),
104
+ ...operation?.extractMatches(event.operation)
105
+ };
106
+ }
107
+ function onOperation(eventType, mutationOrOpts, handler) {
108
+ const { service, connector, operation, opts } = getOpts(mutationOrOpts);
109
+ const servicePattern = service ? new require_common_utilities_path_pattern.PathPattern(service) : undefined;
110
+ const connectorPattern = connector ? new require_common_utilities_path_pattern.PathPattern(connector) : undefined;
111
+ const operationPattern = operation ? new require_common_utilities_path_pattern.PathPattern(operation) : undefined;
112
+ const func = (raw) => {
113
+ const event = raw;
114
+ const params = makeParams(event, servicePattern, connectorPattern, operationPattern);
115
+ const { authtype, authid, service: service$1, connector: connector$1, operation: operation$1,...rest } = event;
116
+ const dataConnectEvent = {
117
+ ...rest,
118
+ authType: authtype,
119
+ authId: authid,
120
+ params
121
+ };
122
+ return require_v2_trace.wrapTraceContext(require_common_onInit.withInit(handler))(dataConnectEvent);
123
+ };
124
+ func.run = handler;
125
+ func.__endpoint = makeEndpoint(eventType, opts, servicePattern, connectorPattern, operationPattern);
126
+ return func;
127
+ }
128
+
129
+ //#endregion
130
+ Object.defineProperty(exports, 'dataconnect_exports', {
131
+ enumerable: true,
132
+ get: function () {
133
+ return dataconnect_exports;
134
+ }
135
+ });
136
+ exports.mutationExecutedEventType = mutationExecutedEventType;
137
+ exports.onMutationExecuted = onMutationExecuted;