firebase-functions 4.6.0 → 4.7.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.
@@ -1,5 +1,12 @@
1
1
  import { App } from "firebase-admin/app";
2
2
  import * as database from "firebase-admin/database";
3
+ /**
4
+ * Pulled from @firebase/database-types, make sure the interface is updated on dependencies upgrades.
5
+ * Represents a child snapshot of a `Reference` that is being iterated over. The key will never be undefined.
6
+ */
7
+ interface IteratedDataSnapshot extends DataSnapshot {
8
+ key: string;
9
+ }
3
10
  /**
4
11
  * Interface representing a Firebase Realtime database data snapshot.
5
12
  */
@@ -97,7 +104,7 @@ export declare class DataSnapshot implements database.DataSnapshot {
97
104
  * @return `true` if enumeration was canceled due to your callback
98
105
  * returning `true`.
99
106
  */
100
- forEach(action: (a: DataSnapshot) => boolean | void): boolean;
107
+ forEach(action: (a: IteratedDataSnapshot) => boolean | void): boolean;
101
108
  /**
102
109
  * Returns `true` if the specified child path has (non-`null`) data.
103
110
  *
@@ -141,3 +148,4 @@ export declare class DataSnapshot implements database.DataSnapshot {
141
148
  /** @hidden */
142
149
  private _fullPath;
143
150
  }
151
+ export {};
@@ -101,6 +101,9 @@ class DataSnapshot {
101
101
  let source = this._data;
102
102
  if (parts.length) {
103
103
  for (const part of parts) {
104
+ if (source[part] === undefined) {
105
+ return null;
106
+ }
104
107
  source = source[part];
105
108
  }
106
109
  }
@@ -3,6 +3,7 @@
3
3
  * @alpha
4
4
  */
5
5
  import { BooleanParam, Expression, IntParam, Param, ParamOptions, SecretParam, StringParam, ListParam } from "./types";
6
+ export { BUCKET_PICKER, TextInput, SelectInput, SelectOptions, MultiSelectInput, select, multiSelect, } from "./types";
6
7
  export { ParamOptions, Expression };
7
8
  type SecretOrExpr = Param<any> | SecretParam;
8
9
  export declare const declaredParams: SecretOrExpr[];
@@ -21,13 +21,17 @@
21
21
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.defineList = exports.defineFloat = exports.defineInt = exports.defineBoolean = exports.defineString = exports.defineSecret = exports.storageBucket = exports.gcloudProject = exports.projectID = exports.databaseURL = exports.clearParams = exports.declaredParams = exports.Expression = void 0;
24
+ exports.defineList = exports.defineFloat = exports.defineInt = exports.defineBoolean = exports.defineString = exports.defineSecret = exports.storageBucket = exports.gcloudProject = exports.projectID = exports.databaseURL = exports.clearParams = exports.declaredParams = exports.Expression = exports.multiSelect = exports.select = exports.BUCKET_PICKER = void 0;
25
25
  /**
26
26
  * @hidden
27
27
  * @alpha
28
28
  */
29
29
  const types_1 = require("./types");
30
30
  Object.defineProperty(exports, "Expression", { enumerable: true, get: function () { return types_1.Expression; } });
31
+ var types_2 = require("./types");
32
+ Object.defineProperty(exports, "BUCKET_PICKER", { enumerable: true, get: function () { return types_2.BUCKET_PICKER; } });
33
+ Object.defineProperty(exports, "select", { enumerable: true, get: function () { return types_2.select; } });
34
+ Object.defineProperty(exports, "multiSelect", { enumerable: true, get: function () { return types_2.multiSelect; } });
31
35
  exports.declaredParams = [];
32
36
  /**
33
37
  * Use a helper to manage the list such that params are uniquely
@@ -30,33 +30,35 @@ export declare class CompareExpression<T extends string | number | boolean | str
30
30
  }
31
31
  /** @hidden */
32
32
  type ParamValueType = "string" | "list" | "boolean" | "int" | "float" | "secret";
33
- type ParamInput<T> = {
34
- text: TextInput<T>;
35
- } | {
36
- select: SelectInput<T>;
37
- } | {
38
- multiSelect: MultiSelectInput;
39
- } | {
40
- resource: ResourceInput;
41
- };
33
+ /** Create a select input from a series of values. */
34
+ export declare function select<T>(options: T[]): SelectInput<T>;
35
+ /** Create a select input from a map of labels to vaues. */
36
+ export declare function select<T>(optionsWithLabels: Record<string, T>): SelectInput<T>;
37
+ /** Create a multi-select input from a series of values. */
38
+ export declare function multiSelect(options: string[]): MultiSelectInput;
39
+ /** Create a multi-select input from map of labels to values. */
40
+ export declare function multiSelect(options: Record<string, string>): MultiSelectInput;
41
+ type ParamInput<T> = TextInput<T> | SelectInput<T> | (T extends string[] ? MultiSelectInput : never) | (T extends string ? ResourceInput : never);
42
42
  /**
43
43
  * Specifies that a Param's value should be determined by prompting the user
44
44
  * to type it in interactively at deploy-time. Input that does not match the
45
45
  * provided validationRegex, if present, will be retried.
46
46
  */
47
47
  export interface TextInput<T = unknown> {
48
- example?: string;
49
- /**
50
- * A regular expression (or an escaped string to compile into a regular
51
- * expression) which the prompted text must satisfy; the prompt will retry
52
- * until input matching the regex is provided.
53
- */
54
- validationRegex?: string | RegExp;
55
- /**
56
- * A custom error message to display when retrying the prompt based on input
57
- * failing to conform to the validationRegex,
58
- */
59
- validationErrorMessage?: string;
48
+ text: {
49
+ example?: string;
50
+ /**
51
+ * A regular expression (or an escaped string to compile into a regular
52
+ * expression) which the prompted text must satisfy; the prompt will retry
53
+ * until input matching the regex is provided.
54
+ */
55
+ validationRegex?: string | RegExp;
56
+ /**
57
+ * A custom error message to display when retrying the prompt based on input
58
+ * failing to conform to the validationRegex,
59
+ */
60
+ validationErrorMessage?: string;
61
+ };
60
62
  }
61
63
  /**
62
64
  * Specifies that a Param's value should be determined by having the user
@@ -65,15 +67,18 @@ export interface TextInput<T = unknown> {
65
67
  */
66
68
  export interface ResourceInput {
67
69
  resource: {
68
- type: string;
70
+ type: "storage.googleapis.com/Bucket";
69
71
  };
70
72
  }
73
+ export declare const BUCKET_PICKER: ResourceInput;
71
74
  /**
72
75
  * Specifies that a Param's value should be determined by having the user select
73
76
  * from a list of pre-canned options interactively at deploy-time.
74
77
  */
75
78
  export interface SelectInput<T = unknown> {
76
- options: Array<SelectOptions<T>>;
79
+ select: {
80
+ options: Array<SelectOptions<T>>;
81
+ };
77
82
  }
78
83
  /**
79
84
  * Specifies that a Param's value should be determined by having the user select
@@ -81,7 +86,9 @@ export interface SelectInput<T = unknown> {
81
86
  * Will result in errors if used on Params of type other than string[].
82
87
  */
83
88
  export interface MultiSelectInput {
84
- options: Array<SelectOptions<string>>;
89
+ multiSelect: {
90
+ options: Array<SelectOptions<string>>;
91
+ };
85
92
  }
86
93
  /**
87
94
  * One of the options provided to a SelectInput, containing a value and
@@ -21,7 +21,7 @@
21
21
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.ListParam = exports.BooleanParam = exports.FloatParam = exports.IntParam = exports.InternalExpression = exports.StringParam = exports.SecretParam = exports.Param = exports.CompareExpression = exports.TernaryExpression = exports.Expression = void 0;
24
+ exports.ListParam = exports.BooleanParam = exports.FloatParam = exports.IntParam = exports.InternalExpression = exports.StringParam = exports.SecretParam = exports.Param = exports.BUCKET_PICKER = exports.multiSelect = exports.select = exports.CompareExpression = exports.TernaryExpression = exports.Expression = void 0;
25
25
  const logger = require("../logger");
26
26
  /*
27
27
  * A CEL expression which can be evaluated during function deployment, and
@@ -142,6 +142,43 @@ class CompareExpression extends Expression {
142
142
  }
143
143
  }
144
144
  exports.CompareExpression = CompareExpression;
145
+ /** Create a select input from a series of values or a map of labels to values */
146
+ function select(options) {
147
+ let wireOpts;
148
+ if (Array.isArray(options)) {
149
+ wireOpts = options.map((opt) => ({ value: opt }));
150
+ }
151
+ else {
152
+ wireOpts = Object.entries(options).map(([label, value]) => ({ label, value }));
153
+ }
154
+ return {
155
+ select: {
156
+ options: wireOpts,
157
+ },
158
+ };
159
+ }
160
+ exports.select = select;
161
+ /** Create a multi-select input from a series of values or map of labels to values. */
162
+ function multiSelect(options) {
163
+ let wireOpts;
164
+ if (Array.isArray(options)) {
165
+ wireOpts = options.map((opt) => ({ value: opt }));
166
+ }
167
+ else {
168
+ wireOpts = Object.entries(options).map(([label, value]) => ({ label, value }));
169
+ }
170
+ return {
171
+ multiSelect: {
172
+ options: wireOpts,
173
+ },
174
+ };
175
+ }
176
+ exports.multiSelect = multiSelect;
177
+ exports.BUCKET_PICKER = {
178
+ resource: {
179
+ type: "storage.googleapis.com/Bucket",
180
+ },
181
+ };
145
182
  /**
146
183
  * Represents a parametrized value that will be read from .env files if present,
147
184
  * or prompted for by the CLI if missing. Instantiate these with the defineX
@@ -159,7 +159,7 @@ export interface StorageEvent extends CloudEvent<StorageObjectData> {
159
159
  /** StorageOptions extend EventHandlerOptions with a bucket name */
160
160
  export interface StorageOptions extends options.EventHandlerOptions {
161
161
  /** The name of the bucket containing this object. */
162
- bucket?: string;
162
+ bucket?: string | Expression<string>;
163
163
  /**
164
164
  * If true, do not deploy or emulate this function.
165
165
  */
@@ -259,7 +259,7 @@ export declare function onObjectArchived(handler: (event: StorageEvent) => any |
259
259
  * @param bucket - The name of the bucket containing this object.
260
260
  * @param handler - Event handler which is run every time a Google Cloud Storage archival occurs.
261
261
  */
262
- export declare function onObjectArchived(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
262
+ export declare function onObjectArchived(bucket: string | Expression<string>, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
263
263
  /**
264
264
  * Event handler sent only when a bucket has enabled object versioning.
265
265
  * This event indicates that the live version of an object has become an
@@ -292,7 +292,7 @@ export declare function onObjectFinalized(handler: (event: StorageEvent) => any
292
292
  * @param bucket - The name of the bucket containing this object.
293
293
  * @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs.
294
294
  */
295
- export declare function onObjectFinalized(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
295
+ export declare function onObjectFinalized(bucket: string | Expression<string>, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
296
296
  /**
297
297
  * Event handler which fires every time a Google Cloud Storage object
298
298
  * creation occurs.
@@ -329,7 +329,7 @@ export declare function onObjectDeleted(handler: (event: StorageEvent) => any |
329
329
  * @param bucket - The name of the bucket containing this object.
330
330
  * @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs.
331
331
  */
332
- export declare function onObjectDeleted(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
332
+ export declare function onObjectDeleted(bucket: string | Expression<string>, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
333
333
  /**
334
334
  * Event handler which fires every time a Google Cloud Storage deletion occurs.
335
335
  *
@@ -358,7 +358,7 @@ export declare function onObjectMetadataUpdated(handler: (event: StorageEvent) =
358
358
  * @param bucket - The name of the bucket containing this object.
359
359
  * @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs.
360
360
  */
361
- export declare function onObjectMetadataUpdated(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
361
+ export declare function onObjectMetadataUpdated(bucket: string | Expression<string>, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
362
362
  /**
363
363
  * Event handler which fires every time the metadata of an existing object
364
364
  * changes.
@@ -161,7 +161,8 @@ function getOptsAndBucket(bucketOrOpts) {
161
161
  var _a;
162
162
  let bucket;
163
163
  let opts;
164
- if (typeof bucketOrOpts === "string") {
164
+ // If bucket is a string or Expression<string>
165
+ if (typeof bucketOrOpts === "string" || "value" in bucketOrOpts) {
165
166
  bucket = bucketOrOpts;
166
167
  opts = {};
167
168
  }
@@ -174,7 +175,7 @@ function getOptsAndBucket(bucketOrOpts) {
174
175
  throw new Error("Missing bucket name. If you are unit testing, please provide a bucket name" +
175
176
  " by providing bucket name directly in the event handler or by setting process.env.FIREBASE_CONFIG.");
176
177
  }
177
- if (!/^[a-z\d][a-z\d\\._-]{1,230}[a-z\d]$/.test(bucket)) {
178
+ if (typeof bucket === "string" && !/^[a-z\d][a-z\d\\._-]{1,230}[a-z\d]$/.test(bucket)) {
178
179
  throw new Error(`Invalid bucket name ${bucket}`);
179
180
  }
180
181
  return [opts, bucket];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-functions",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "description": "Firebase SDK for Cloud Functions",
5
5
  "keywords": [
6
6
  "firebase",