firebase-functions 6.5.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 (157) 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 +19 -4
  101. package/lib/params/index.js +153 -129
  102. package/lib/params/types.d.ts +17 -0
  103. package/lib/params/types.js +390 -382
  104. package/lib/runtime/loader.js +114 -148
  105. package/lib/runtime/manifest.js +106 -126
  106. package/lib/types/global.d.js +0 -0
  107. package/lib/v1/cloud-functions.d.ts +2 -2
  108. package/lib/v1/cloud-functions.js +193 -241
  109. package/lib/v1/config.d.ts +4 -7
  110. package/lib/v1/config.js +13 -75
  111. package/lib/v1/function-builder.js +239 -368
  112. package/lib/v1/function-configuration.js +70 -63
  113. package/lib/v1/index.js +118 -73
  114. package/lib/v1/providers/analytics.js +189 -210
  115. package/lib/v1/providers/auth.d.ts +2 -1
  116. package/lib/v1/providers/auth.js +159 -164
  117. package/lib/v1/providers/database.js +237 -242
  118. package/lib/v1/providers/firestore.js +131 -130
  119. package/lib/v1/providers/https.d.ts +2 -1
  120. package/lib/v1/providers/https.js +79 -86
  121. package/lib/v1/providers/pubsub.js +175 -172
  122. package/lib/v1/providers/remoteConfig.js +64 -68
  123. package/lib/v1/providers/storage.js +161 -163
  124. package/lib/v1/providers/tasks.d.ts +1 -1
  125. package/lib/v1/providers/tasks.js +65 -80
  126. package/lib/v1/providers/testLab.js +94 -94
  127. package/lib/v2/core.d.ts +1 -1
  128. package/lib/v2/core.js +5 -32
  129. package/lib/v2/index.d.ts +6 -3
  130. package/lib/v2/index.js +123 -75
  131. package/lib/v2/options.js +88 -114
  132. package/lib/v2/providers/alerts/alerts.js +76 -95
  133. package/lib/v2/providers/alerts/appDistribution.js +73 -78
  134. package/lib/v2/providers/alerts/billing.js +49 -53
  135. package/lib/v2/providers/alerts/crashlytics.js +110 -102
  136. package/lib/v2/providers/alerts/index.js +56 -53
  137. package/lib/v2/providers/alerts/performance.js +64 -74
  138. package/lib/v2/providers/database.js +177 -180
  139. package/lib/v2/providers/dataconnect.d.ts +95 -0
  140. package/lib/v2/providers/dataconnect.js +137 -0
  141. package/lib/v2/providers/eventarc.js +55 -77
  142. package/lib/v2/providers/firestore.js +262 -260
  143. package/lib/v2/providers/https.d.ts +3 -2
  144. package/lib/v2/providers/https.js +210 -247
  145. package/lib/v2/providers/identity.d.ts +2 -1
  146. package/lib/v2/providers/identity.js +96 -105
  147. package/lib/v2/providers/pubsub.js +149 -167
  148. package/lib/v2/providers/remoteConfig.js +54 -63
  149. package/lib/v2/providers/scheduler.js +84 -96
  150. package/lib/v2/providers/storage.js +147 -162
  151. package/lib/v2/providers/tasks.d.ts +1 -1
  152. package/lib/v2/providers/tasks.js +68 -95
  153. package/lib/v2/providers/testLab.js +55 -64
  154. package/lib/v2/trace.js +18 -19
  155. package/package.json +290 -226
  156. package/protos/compiledFirestore.mjs +3512 -0
  157. package/protos/update.sh +28 -7
@@ -0,0 +1,400 @@
1
+ import { warn } from "../logger/index.mjs";
2
+
3
+ //#region src/params/types.ts
4
+ var Expression = class {
5
+ /** Returns the expression's runtime value, based on the CLI's resolution of parameters. */
6
+ value() {
7
+ if (process.env.FUNCTIONS_CONTROL_API === "true") {
8
+ warn(`${this.toString()}.value() invoked during function deployment, instead of during runtime.`);
9
+ warn(`This is usually a mistake. In configs, use Params directly without calling .value().`);
10
+ warn(`example: { memory: memoryParam } not { memory: memoryParam.value() }`);
11
+ }
12
+ return this.runtimeValue();
13
+ }
14
+ /** @internal */
15
+ runtimeValue() {
16
+ throw new Error("Not implemented");
17
+ }
18
+ /** Returns the expression's representation as a braced CEL expression. */
19
+ toCEL() {
20
+ return `{{ ${this.toString()} }}`;
21
+ }
22
+ /** Returns the expression's representation as JSON. */
23
+ toJSON() {
24
+ return this.toString();
25
+ }
26
+ };
27
+ function valueOf(arg) {
28
+ return arg instanceof Expression ? arg.runtimeValue() : arg;
29
+ }
30
+ /**
31
+ * Returns how an entity (either an `Expression` or a literal value) should be represented in CEL.
32
+ * - Expressions delegate to the `.toString()` method, which is used by the WireManifest
33
+ * - Strings have to be quoted explicitly
34
+ * - Arrays are represented as []-delimited, parsable JSON
35
+ * - Numbers and booleans are not quoted explicitly
36
+ */
37
+ function refOf(arg) {
38
+ if (arg instanceof Expression) {
39
+ return arg.toString();
40
+ } else if (typeof arg === "string") {
41
+ return `"${arg}"`;
42
+ } else if (Array.isArray(arg)) {
43
+ return JSON.stringify(arg);
44
+ } else {
45
+ return arg.toString();
46
+ }
47
+ }
48
+ /**
49
+ * A CEL expression corresponding to a ternary operator, e.g {{ cond ? ifTrue : ifFalse }}
50
+ */
51
+ var TernaryExpression = class extends Expression {
52
+ constructor(test, ifTrue, ifFalse) {
53
+ super();
54
+ this.test = test;
55
+ this.ifTrue = ifTrue;
56
+ this.ifFalse = ifFalse;
57
+ this.ifTrue = ifTrue;
58
+ this.ifFalse = ifFalse;
59
+ }
60
+ /** @internal */
61
+ runtimeValue() {
62
+ return this.test.runtimeValue() ? valueOf(this.ifTrue) : valueOf(this.ifFalse);
63
+ }
64
+ toString() {
65
+ return `${this.test} ? ${refOf(this.ifTrue)} : ${refOf(this.ifFalse)}`;
66
+ }
67
+ };
68
+ /**
69
+ * A CEL expression that evaluates to boolean true or false based on a comparison
70
+ * between the value of another expression and a literal of that same type.
71
+ */
72
+ var CompareExpression = class extends Expression {
73
+ constructor(cmp, lhs, rhs) {
74
+ super();
75
+ this.cmp = cmp;
76
+ this.lhs = lhs;
77
+ this.rhs = rhs;
78
+ }
79
+ /** @internal */
80
+ runtimeValue() {
81
+ const left = this.lhs.runtimeValue();
82
+ const right = valueOf(this.rhs);
83
+ switch (this.cmp) {
84
+ case "==": return Array.isArray(left) ? this.arrayEquals(left, right) : left === right;
85
+ case "!=": return Array.isArray(left) ? !this.arrayEquals(left, right) : left !== right;
86
+ case ">": return left > right;
87
+ case ">=": return left >= right;
88
+ case "<": return left < right;
89
+ case "<=": return left <= right;
90
+ default: throw new Error(`Unknown comparator ${this.cmp}`);
91
+ }
92
+ }
93
+ /** @internal */
94
+ arrayEquals(a, b) {
95
+ return a.every((item) => b.includes(item)) && b.every((item) => a.includes(item));
96
+ }
97
+ toString() {
98
+ const rhsStr = refOf(this.rhs);
99
+ return `${this.lhs} ${this.cmp} ${rhsStr}`;
100
+ }
101
+ /** Returns a `TernaryExpression` which can resolve to one of two values, based on the resolution of this comparison. */
102
+ thenElse(ifTrue, ifFalse) {
103
+ return new TernaryExpression(this, ifTrue, ifFalse);
104
+ }
105
+ };
106
+ /** Create a select input from a series of values or a map of labels to values */
107
+ function select(options) {
108
+ let wireOpts;
109
+ if (Array.isArray(options)) {
110
+ wireOpts = options.map((opt) => ({ value: opt }));
111
+ } else {
112
+ wireOpts = Object.entries(options).map(([label, value]) => ({
113
+ label,
114
+ value
115
+ }));
116
+ }
117
+ return { select: { options: wireOpts } };
118
+ }
119
+ /** Create a multi-select input from a series of values or map of labels to values. */
120
+ function multiSelect(options) {
121
+ let wireOpts;
122
+ if (Array.isArray(options)) {
123
+ wireOpts = options.map((opt) => ({ value: opt }));
124
+ } else {
125
+ wireOpts = Object.entries(options).map(([label, value]) => ({
126
+ label,
127
+ value
128
+ }));
129
+ }
130
+ return { multiSelect: { options: wireOpts } };
131
+ }
132
+ /**
133
+ * Autogenerate a list of buckets in a project that a user can select from.
134
+ */
135
+ const BUCKET_PICKER = { resource: { type: "storage.googleapis.com/Bucket" } };
136
+ /**
137
+ * Represents a parametrized value that will be read from .env files if present,
138
+ * or prompted for by the CLI if missing. Instantiate these with the defineX
139
+ * methods exported by the firebase-functions/params namespace.
140
+ */
141
+ var Param = class extends Expression {
142
+ static {
143
+ this.type = "string";
144
+ }
145
+ constructor(name, options = {}) {
146
+ super();
147
+ this.name = name;
148
+ this.options = options;
149
+ }
150
+ /** @internal */
151
+ runtimeValue() {
152
+ throw new Error("Not implemented");
153
+ }
154
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
155
+ cmp(cmp, rhs) {
156
+ return new CompareExpression(cmp, this, rhs);
157
+ }
158
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
159
+ equals(rhs) {
160
+ return this.cmp("==", rhs);
161
+ }
162
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
163
+ notEquals(rhs) {
164
+ return this.cmp("!=", rhs);
165
+ }
166
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
167
+ greaterThan(rhs) {
168
+ return this.cmp(">", rhs);
169
+ }
170
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
171
+ greaterThanOrEqualTo(rhs) {
172
+ return this.cmp(">=", rhs);
173
+ }
174
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
175
+ lessThan(rhs) {
176
+ return this.cmp("<", rhs);
177
+ }
178
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
179
+ lessThanOrEqualTo(rhs) {
180
+ return this.cmp("<=", rhs);
181
+ }
182
+ /**
183
+ * Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression.
184
+ * @deprecated A typo. Use lessThanOrEqualTo instead.
185
+ */
186
+ lessThanorEqualTo(rhs) {
187
+ return this.lessThanOrEqualTo(rhs);
188
+ }
189
+ toString() {
190
+ return `params.${this.name}`;
191
+ }
192
+ /** @internal */
193
+ toSpec() {
194
+ const { default: paramDefault,...otherOptions } = this.options;
195
+ const out = {
196
+ name: this.name,
197
+ ...otherOptions,
198
+ type: this.constructor.type
199
+ };
200
+ if (paramDefault instanceof Expression) {
201
+ out.default = paramDefault.toCEL();
202
+ } else if (paramDefault !== undefined) {
203
+ out.default = paramDefault;
204
+ }
205
+ if (out.input && "text" in out.input && out.input.text.validationRegex instanceof RegExp) {
206
+ out.input.text.validationRegex = out.input.text.validationRegex.source;
207
+ }
208
+ return out;
209
+ }
210
+ };
211
+ /**
212
+ * A parametrized string whose value is stored in Cloud Secret Manager
213
+ * instead of the local filesystem. Supply instances of SecretParams to
214
+ * the secrets array while defining a Function to make their values accessible
215
+ * during execution of that Function.
216
+ */
217
+ var SecretParam = class {
218
+ static {
219
+ this.type = "secret";
220
+ }
221
+ constructor(name) {
222
+ this.name = name;
223
+ }
224
+ /** @internal */
225
+ runtimeValue() {
226
+ const val = process.env[this.name];
227
+ if (val === undefined) {
228
+ warn(`No value found for secret parameter "${this.name}". A function can only access a secret if you include the secret in the function's dependency array.`);
229
+ }
230
+ return val || "";
231
+ }
232
+ /** @internal */
233
+ toSpec() {
234
+ return {
235
+ type: "secret",
236
+ name: this.name
237
+ };
238
+ }
239
+ /** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
240
+ value() {
241
+ if (process.env.FUNCTIONS_CONTROL_API === "true") {
242
+ throw new Error(`Cannot access the value of secret "${this.name}" during function deployment. Secret values are only available at runtime.`);
243
+ }
244
+ return this.runtimeValue();
245
+ }
246
+ };
247
+ /**
248
+ * A parametrized object whose value is stored as a JSON string in Cloud Secret Manager.
249
+ * This is useful for managing groups of related configuration values, such as all settings
250
+ * for a third-party API, as a single unit. Supply instances of JsonSecretParam to the
251
+ * secrets array while defining a Function to make their values accessible during execution
252
+ * of that Function.
253
+ */
254
+ var JsonSecretParam = class {
255
+ static {
256
+ this.type = "secret";
257
+ }
258
+ constructor(name) {
259
+ this.name = name;
260
+ }
261
+ /** @internal */
262
+ runtimeValue() {
263
+ const val = process.env[this.name];
264
+ if (val === undefined) {
265
+ throw new Error(`No value found for secret parameter "${this.name}". A function can only access a secret if you include the secret in the function's dependency array.`);
266
+ }
267
+ try {
268
+ return JSON.parse(val);
269
+ } catch (error) {
270
+ throw new Error(`"${this.name}" could not be parsed as JSON. Please verify its value in Secret Manager. Details: ${error}`);
271
+ }
272
+ }
273
+ /** @internal */
274
+ toSpec() {
275
+ return {
276
+ type: "secret",
277
+ name: this.name,
278
+ format: "json"
279
+ };
280
+ }
281
+ /** Returns the secret's parsed JSON value at runtime. Throws an error if accessed during deployment, if the secret is not set, or if the value is not valid JSON. */
282
+ value() {
283
+ if (process.env.FUNCTIONS_CONTROL_API === "true") {
284
+ throw new Error(`Cannot access the value of secret "${this.name}" during function deployment. Secret values are only available at runtime.`);
285
+ }
286
+ return this.runtimeValue();
287
+ }
288
+ };
289
+ /**
290
+ * A parametrized value of String type that will be read from .env files
291
+ * if present, or prompted for by the CLI if missing.
292
+ */
293
+ var StringParam = class extends Param {
294
+ /** @internal */
295
+ runtimeValue() {
296
+ return process.env[this.name] || "";
297
+ }
298
+ };
299
+ /**
300
+ * A CEL expression which represents an internal Firebase variable. This class
301
+ * cannot be instantiated by developers, but we provide several canned instances
302
+ * of it to make available parameters that will never have to be defined at
303
+ * deployment time, and can always be read from process.env.
304
+ * @internal
305
+ */
306
+ var InternalExpression = class extends Param {
307
+ constructor(name, getter) {
308
+ super(name);
309
+ this.getter = getter;
310
+ }
311
+ /** @internal */
312
+ runtimeValue() {
313
+ return this.getter(process.env) || "";
314
+ }
315
+ toSpec() {
316
+ throw new Error("An InternalExpression should never be marshalled for wire transmission.");
317
+ }
318
+ };
319
+ /**
320
+ * A parametrized value of Integer type that will be read from .env files
321
+ * if present, or prompted for by the CLI if missing.
322
+ */
323
+ var IntParam = class extends Param {
324
+ static {
325
+ this.type = "int";
326
+ }
327
+ /** @internal */
328
+ runtimeValue() {
329
+ return parseInt(process.env[this.name] || "0", 10) || 0;
330
+ }
331
+ };
332
+ /**
333
+ * A parametrized value of Float type that will be read from .env files
334
+ * if present, or prompted for by the CLI if missing.
335
+ */
336
+ var FloatParam = class extends Param {
337
+ static {
338
+ this.type = "float";
339
+ }
340
+ /** @internal */
341
+ runtimeValue() {
342
+ return parseFloat(process.env[this.name] || "0") || 0;
343
+ }
344
+ };
345
+ /**
346
+ * A parametrized value of Boolean type that will be read from .env files
347
+ * if present, or prompted for by the CLI if missing.
348
+ */
349
+ var BooleanParam = class extends Param {
350
+ static {
351
+ this.type = "boolean";
352
+ }
353
+ /** @internal */
354
+ runtimeValue() {
355
+ return !!process.env[this.name] && process.env[this.name] === "true";
356
+ }
357
+ /** @deprecated */
358
+ then(ifTrue, ifFalse) {
359
+ return this.thenElse(ifTrue, ifFalse);
360
+ }
361
+ thenElse(ifTrue, ifFalse) {
362
+ return new TernaryExpression(this, ifTrue, ifFalse);
363
+ }
364
+ };
365
+ /**
366
+ * A parametrized value of String[] type that will be read from .env files
367
+ * if present, or prompted for by the CLI if missing.
368
+ */
369
+ var ListParam = class extends Param {
370
+ static {
371
+ this.type = "list";
372
+ }
373
+ /** @internal */
374
+ runtimeValue() {
375
+ const val = JSON.parse(process.env[this.name]);
376
+ if (!Array.isArray(val) || !val.every((v) => typeof v === "string")) {
377
+ return [];
378
+ }
379
+ return val;
380
+ }
381
+ /** @hidden */
382
+ greaterThan(rhs) {
383
+ throw new Error(">/< comparison operators not supported on params of type List");
384
+ }
385
+ /** @hidden */
386
+ greaterThanOrEqualTo(rhs) {
387
+ throw new Error(">/< comparison operators not supported on params of type List");
388
+ }
389
+ /** @hidden */
390
+ lessThan(rhs) {
391
+ throw new Error(">/< comparison operators not supported on params of type List");
392
+ }
393
+ /** @hidden */
394
+ lessThanorEqualTo(rhs) {
395
+ throw new Error(">/< comparison operators not supported on params of type List");
396
+ }
397
+ };
398
+
399
+ //#endregion
400
+ export { BUCKET_PICKER, BooleanParam, CompareExpression, Expression, FloatParam, IntParam, InternalExpression, JsonSecretParam, ListParam, Param, SecretParam, StringParam, TernaryExpression, multiSelect, select };
@@ -0,0 +1,132 @@
1
+ import { __require } from "../_virtual/rolldown_runtime.mjs";
2
+ import { declaredParams } from "../params/index.mjs";
3
+ import * as path from "path";
4
+ import * as url from "url";
5
+
6
+ //#region src/runtime/loader.ts
7
+ /**
8
+ * Dynamically load import function to prevent TypeScript from
9
+ * transpiling into a require.
10
+ *
11
+ * See https://github.com/microsoft/TypeScript/issues/43329.
12
+ *
13
+ */
14
+ const dynamicImport = new Function("modulePath", "return import(modulePath)");
15
+ async function loadModule(functionsDir) {
16
+ const absolutePath = path.resolve(functionsDir);
17
+ try {
18
+ return __require(path.resolve(absolutePath));
19
+ } catch (e) {
20
+ if (e.code === "ERR_REQUIRE_ESM" || e.code === "ERR_REQUIRE_ASYNC_MODULE") {
21
+ const modulePath = __require.resolve(absolutePath);
22
+ const moduleURL = url.pathToFileURL(modulePath).href;
23
+ return await dynamicImport(moduleURL);
24
+ }
25
+ throw e;
26
+ }
27
+ }
28
+ function extractStack(module, endpoints, requiredAPIs, extensions, prefix = "") {
29
+ for (const [name, valAsUnknown] of Object.entries(module)) {
30
+ const val = valAsUnknown;
31
+ if (typeof val === "function" && val.__endpoint && typeof val.__endpoint === "object") {
32
+ const funcName = prefix + name;
33
+ endpoints[funcName] = {
34
+ ...val.__endpoint,
35
+ entryPoint: funcName.replace(/-/g, ".")
36
+ };
37
+ if (val.__requiredAPIs && Array.isArray(val.__requiredAPIs)) {
38
+ requiredAPIs.push(...val.__requiredAPIs);
39
+ }
40
+ } else if (isFirebaseRefExtension(val)) {
41
+ extensions[val.instanceId] = {
42
+ params: convertExtensionParams(val.params),
43
+ ref: val.FIREBASE_EXTENSION_REFERENCE,
44
+ events: val.events || []
45
+ };
46
+ } else if (isFirebaseLocalExtension(val)) {
47
+ extensions[val.instanceId] = {
48
+ params: convertExtensionParams(val.params),
49
+ localPath: val.FIREBASE_EXTENSION_LOCAL_PATH,
50
+ events: val.events || []
51
+ };
52
+ } else if (isObject(val)) {
53
+ extractStack(val, endpoints, requiredAPIs, extensions, prefix + name + "-");
54
+ }
55
+ }
56
+ }
57
+ function toTitleCase(txt) {
58
+ return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
59
+ }
60
+ function snakeToCamelCase(txt) {
61
+ let ret = txt.toLowerCase();
62
+ ret = ret.replace(/_/g, " ");
63
+ ret = ret.replace(/\w\S*/g, toTitleCase);
64
+ ret = ret.charAt(0).toLowerCase() + ret.substring(1);
65
+ return ret;
66
+ }
67
+ function convertExtensionParams(params) {
68
+ const systemPrefixes = {
69
+ FUNCTION: "firebaseextensions.v1beta.function",
70
+ V2FUNCTION: "firebaseextensions.v1beta.v2function"
71
+ };
72
+ const converted = {};
73
+ for (const [rawKey, paramVal] of Object.entries(params)) {
74
+ let key = rawKey;
75
+ if (rawKey.startsWith("_") && rawKey !== "_EVENT_ARC_REGION") {
76
+ const prefix = rawKey.substring(1).split("_")[0];
77
+ const suffix = rawKey.substring(2 + prefix.length);
78
+ key = `${systemPrefixes[prefix]}/${snakeToCamelCase(suffix)}`;
79
+ }
80
+ if (Array.isArray(paramVal)) {
81
+ converted[key] = paramVal.join(",");
82
+ } else {
83
+ converted[key] = paramVal;
84
+ }
85
+ }
86
+ return converted;
87
+ }
88
+ function isObject(value) {
89
+ return typeof value === "object" && value !== null;
90
+ }
91
+ const isFirebaseLocalExtension = (val) => {
92
+ return isObject(val) && typeof val.FIREBASE_EXTENSION_LOCAL_PATH === "string" && typeof val.instanceId === "string" && isObject(val.params) && (!val.events || Array.isArray(val.events));
93
+ };
94
+ const isFirebaseRefExtension = (val) => {
95
+ return isObject(val) && typeof val.FIREBASE_EXTENSION_REFERENCE === "string" && typeof val.instanceId === "string" && isObject(val.params) && (!val.events || Array.isArray(val.events));
96
+ };
97
+ function mergeRequiredAPIs(requiredAPIs) {
98
+ const apiToReasons = {};
99
+ for (const { api, reason } of requiredAPIs) {
100
+ const reasons = apiToReasons[api] || new Set();
101
+ reasons.add(reason);
102
+ apiToReasons[api] = reasons;
103
+ }
104
+ const merged = [];
105
+ for (const [api, reasons] of Object.entries(apiToReasons)) {
106
+ merged.push({
107
+ api,
108
+ reason: Array.from(reasons).join(" ")
109
+ });
110
+ }
111
+ return merged;
112
+ }
113
+ async function loadStack(functionsDir) {
114
+ const endpoints = {};
115
+ const requiredAPIs = [];
116
+ const extensions = {};
117
+ const mod = await loadModule(functionsDir);
118
+ extractStack(mod, endpoints, requiredAPIs, extensions);
119
+ const stack = {
120
+ endpoints,
121
+ specVersion: "v1alpha1",
122
+ requiredAPIs: mergeRequiredAPIs(requiredAPIs),
123
+ extensions
124
+ };
125
+ if (declaredParams.length > 0) {
126
+ stack.params = declaredParams.map((p) => p.toSpec());
127
+ }
128
+ return stack;
129
+ }
130
+
131
+ //#endregion
132
+ export { extractStack, loadStack, mergeRequiredAPIs };
@@ -0,0 +1,134 @@
1
+ import { Expression } from "../params/types.mjs";
2
+ import "../params/index.mjs";
3
+ import { RESET_VALUE, ResetValue } from "../common/options.mjs";
4
+
5
+ //#region src/runtime/manifest.ts
6
+ /**
7
+ * Returns the JSON representation of a ManifestStack, which has CEL
8
+ * expressions in its options as object types, with its expressions
9
+ * transformed into the actual CEL strings.
10
+ *
11
+ * @alpha
12
+ */
13
+ function stackToWire(stack) {
14
+ const wireStack = stack;
15
+ const traverse = function traverse$1(obj) {
16
+ for (const [key, val] of Object.entries(obj)) {
17
+ if (val instanceof Expression) {
18
+ obj[key] = val.toCEL();
19
+ } else if (val instanceof ResetValue) {
20
+ obj[key] = val.toJSON();
21
+ } else if (typeof val === "object" && val !== null) {
22
+ traverse$1(val);
23
+ }
24
+ }
25
+ };
26
+ traverse(wireStack.endpoints);
27
+ return wireStack;
28
+ }
29
+ const RESETTABLE_OPTIONS = {
30
+ availableMemoryMb: null,
31
+ timeoutSeconds: null,
32
+ minInstances: null,
33
+ maxInstances: null,
34
+ ingressSettings: null,
35
+ concurrency: null,
36
+ serviceAccountEmail: null,
37
+ vpc: null
38
+ };
39
+ function initEndpoint(resetOptions, ...opts) {
40
+ const endpoint = {};
41
+ if (opts.every((opt) => !opt?.preserveExternalChanges)) {
42
+ for (const key of Object.keys(resetOptions)) {
43
+ endpoint[key] = RESET_VALUE;
44
+ }
45
+ }
46
+ return endpoint;
47
+ }
48
+ /**
49
+ * @internal
50
+ */
51
+ function initV1Endpoint(...opts) {
52
+ const { concurrency,...resetOpts } = RESETTABLE_OPTIONS;
53
+ return initEndpoint({ ...resetOpts }, ...opts);
54
+ }
55
+ /**
56
+ * @internal
57
+ */
58
+ function initV2Endpoint(...opts) {
59
+ return initEndpoint(RESETTABLE_OPTIONS, ...opts);
60
+ }
61
+ const RESETTABLE_RETRY_CONFIG_OPTIONS = {
62
+ maxAttempts: null,
63
+ maxDoublings: null,
64
+ maxBackoffSeconds: null,
65
+ maxRetrySeconds: null,
66
+ minBackoffSeconds: null
67
+ };
68
+ const RESETTABLE_RATE_LIMITS_OPTIONS = {
69
+ maxConcurrentDispatches: null,
70
+ maxDispatchesPerSecond: null
71
+ };
72
+ /**
73
+ * @internal
74
+ */
75
+ function initTaskQueueTrigger(...opts) {
76
+ const taskQueueTrigger = {
77
+ retryConfig: {},
78
+ rateLimits: {}
79
+ };
80
+ if (opts.every((opt) => !opt?.preserveExternalChanges)) {
81
+ for (const key of Object.keys(RESETTABLE_RETRY_CONFIG_OPTIONS)) {
82
+ taskQueueTrigger.retryConfig[key] = RESET_VALUE;
83
+ }
84
+ for (const key of Object.keys(RESETTABLE_RATE_LIMITS_OPTIONS)) {
85
+ taskQueueTrigger.rateLimits[key] = RESET_VALUE;
86
+ }
87
+ }
88
+ return taskQueueTrigger;
89
+ }
90
+ const RESETTABLE_V1_SCHEDULE_OPTIONS = {
91
+ retryCount: null,
92
+ maxDoublings: null,
93
+ maxRetryDuration: null,
94
+ maxBackoffDuration: null,
95
+ minBackoffDuration: null
96
+ };
97
+ const RESETTABLE_V2_SCHEDULE_OPTIONS = {
98
+ retryCount: null,
99
+ maxDoublings: null,
100
+ maxRetrySeconds: null,
101
+ minBackoffSeconds: null,
102
+ maxBackoffSeconds: null
103
+ };
104
+ function initScheduleTrigger(resetOptions, schedule, ...opts) {
105
+ let scheduleTrigger = {
106
+ schedule,
107
+ retryConfig: {}
108
+ };
109
+ if (opts.every((opt) => !opt?.preserveExternalChanges)) {
110
+ for (const key of Object.keys(resetOptions)) {
111
+ scheduleTrigger.retryConfig[key] = RESET_VALUE;
112
+ }
113
+ scheduleTrigger = {
114
+ ...scheduleTrigger,
115
+ timeZone: RESET_VALUE
116
+ };
117
+ }
118
+ return scheduleTrigger;
119
+ }
120
+ /**
121
+ * @internal
122
+ */
123
+ function initV1ScheduleTrigger(schedule, ...opts) {
124
+ return initScheduleTrigger(RESETTABLE_V1_SCHEDULE_OPTIONS, schedule, ...opts);
125
+ }
126
+ /**
127
+ * @internal
128
+ */
129
+ function initV2ScheduleTrigger(schedule, ...opts) {
130
+ return initScheduleTrigger(RESETTABLE_V2_SCHEDULE_OPTIONS, schedule, ...opts);
131
+ }
132
+
133
+ //#endregion
134
+ export { initTaskQueueTrigger, initV1Endpoint, initV1ScheduleTrigger, initV2Endpoint, initV2ScheduleTrigger, stackToWire };
@@ -0,0 +1 @@
1
+ export { };