firebase-functions 4.2.1 → 4.3.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 (46) hide show
  1. package/lib/common/change.js +4 -4
  2. package/lib/common/encoding.d.ts +3 -2
  3. package/lib/common/encoding.js +4 -0
  4. package/lib/common/params.d.ts +4 -4
  5. package/lib/common/providers/firestore.d.ts +1 -0
  6. package/lib/common/providers/firestore.js +106 -0
  7. package/lib/common/providers/https.d.ts +3 -3
  8. package/lib/common/providers/identity.d.ts +3 -3
  9. package/lib/common/providers/tasks.d.ts +1 -1
  10. package/lib/common/timezone.d.ts +1 -1
  11. package/lib/common/utilities/path-pattern.js +5 -5
  12. package/lib/logger/index.d.ts +1 -1
  13. package/lib/params/index.d.ts +1 -1
  14. package/lib/params/types.d.ts +5 -5
  15. package/lib/v1/function-builder.d.ts +4 -2
  16. package/lib/v1/function-builder.js +7 -5
  17. package/lib/v1/function-configuration.d.ts +5 -5
  18. package/lib/v1/index.d.ts +2 -0
  19. package/lib/v1/index.js +4 -1
  20. package/lib/v1/providers/auth.js +3 -3
  21. package/lib/v1/providers/firestore.d.ts +2 -2
  22. package/lib/v1/providers/firestore.js +4 -39
  23. package/lib/v1/providers/testLab.d.ts +3 -3
  24. package/lib/v2/index.d.ts +4 -1
  25. package/lib/v2/index.js +6 -1
  26. package/lib/v2/options.d.ts +8 -8
  27. package/lib/v2/providers/alerts/alerts.d.ts +3 -3
  28. package/lib/v2/providers/alerts/appDistribution.d.ts +2 -2
  29. package/lib/v2/providers/alerts/crashlytics.d.ts +2 -2
  30. package/lib/v2/providers/database.d.ts +3 -3
  31. package/lib/v2/providers/eventarc.d.ts +2 -2
  32. package/lib/v2/providers/firestore.d.ts +92 -0
  33. package/lib/v2/providers/firestore.js +244 -0
  34. package/lib/v2/providers/https.d.ts +3 -3
  35. package/lib/v2/providers/identity.d.ts +2 -2
  36. package/lib/v2/providers/pubsub.d.ts +2 -2
  37. package/lib/v2/providers/remoteConfig.d.ts +2 -2
  38. package/lib/v2/providers/storage.d.ts +2 -2
  39. package/lib/v2/providers/tasks.d.ts +3 -3
  40. package/lib/v2/providers/testLab.d.ts +2 -2
  41. package/lib/v2/trace.d.ts +1 -1
  42. package/package.json +13 -6
  43. package/protos/README.md +15 -0
  44. package/protos/compiledFirestore.d.ts +1342 -0
  45. package/protos/compiledFirestore.js +3514 -0
  46. package/protos/update.sh +75 -0
@@ -5,19 +5,19 @@ export { RESET_VALUE } from "../common/options";
5
5
  /**
6
6
  * List of all regions supported by Cloud Functions v2
7
7
  */
8
- export declare type SupportedRegion = "asia-northeast1" | "europe-north1" | "europe-west1" | "europe-west4" | "us-central1" | "us-east1" | "us-west1";
8
+ export type SupportedRegion = "asia-northeast1" | "europe-north1" | "europe-west1" | "europe-west4" | "us-central1" | "us-east1" | "us-west1";
9
9
  /**
10
10
  * List of available memory options supported by Cloud Functions.
11
11
  */
12
- export declare type MemoryOption = "128MiB" | "256MiB" | "512MiB" | "1GiB" | "2GiB" | "4GiB" | "8GiB" | "16GiB" | "32GiB";
12
+ export type MemoryOption = "128MiB" | "256MiB" | "512MiB" | "1GiB" | "2GiB" | "4GiB" | "8GiB" | "16GiB" | "32GiB";
13
13
  /**
14
14
  * List of available options for VpcConnectorEgressSettings.
15
15
  */
16
- export declare type VpcEgressSetting = "PRIVATE_RANGES_ONLY" | "ALL_TRAFFIC";
16
+ export type VpcEgressSetting = "PRIVATE_RANGES_ONLY" | "ALL_TRAFFIC";
17
17
  /**
18
18
  * List of available options for IngressSettings.
19
19
  */
20
- export declare type IngressSetting = "ALLOW_ALL" | "ALLOW_INTERNAL_ONLY" | "ALLOW_INTERNAL_AND_GCLB";
20
+ export type IngressSetting = "ALLOW_ALL" | "ALLOW_INTERNAL_ONLY" | "ALLOW_INTERNAL_AND_GCLB";
21
21
  /**
22
22
  * GlobalOptions are options that can be set across an entire project.
23
23
  * These options are common to HTTPS and Event handling functions.
@@ -30,7 +30,7 @@ export interface GlobalOptions {
30
30
  /**
31
31
  * Region where functions should be deployed.
32
32
  */
33
- region?: SupportedRegion | string;
33
+ region?: SupportedRegion | string | Expression<string> | ResetValue;
34
34
  /**
35
35
  * Amount of memory to allocate to a function.
36
36
  */
@@ -91,7 +91,7 @@ export interface GlobalOptions {
91
91
  /**
92
92
  * Specific service account for the function to run as.
93
93
  */
94
- serviceAccount?: string | ResetValue;
94
+ serviceAccount?: string | Expression<string> | ResetValue;
95
95
  /**
96
96
  * Ingress settings which control where this function can be called from.
97
97
  */
@@ -140,9 +140,9 @@ export interface EventHandlerOptions extends Omit<GlobalOptions, "enforceAppChec
140
140
  /** Whether failed executions should be delivered again. */
141
141
  retry?: boolean | Expression<boolean> | ResetValue;
142
142
  /** Region of the EventArc trigger. */
143
- region?: string;
143
+ region?: string | Expression<string> | ResetValue;
144
144
  /** The service account that EventArc should use to invoke this function. Requires the P4SA to have ActAs permission on this service account. */
145
- serviceAccount?: string | ResetValue;
145
+ serviceAccount?: string | Expression<string> | ResetValue;
146
146
  /** The name of the channel where the function receives events. */
147
147
  channel?: string;
148
148
  }
@@ -31,7 +31,7 @@ export interface AlertEvent<T> extends CloudEvent<FirebaseAlertData<T>> {
31
31
  data: FirebaseAlertData<T>;
32
32
  }
33
33
  /** The underlying alert type of the Firebase Alerts provider. */
34
- export declare type AlertType = "crashlytics.newFatalIssue" | "crashlytics.newNonfatalIssue" | "crashlytics.regression" | "crashlytics.stabilityDigest" | "crashlytics.velocity" | "crashlytics.newAnrIssue" | "billing.planUpdate" | "billing.automatedPlanUpdate" | "appDistribution.newTesterIosDevice" | "appDistribution.inAppFeedback" | "performance.threshold" | string;
34
+ export type AlertType = "crashlytics.newFatalIssue" | "crashlytics.newNonfatalIssue" | "crashlytics.regression" | "crashlytics.stabilityDigest" | "crashlytics.velocity" | "crashlytics.newAnrIssue" | "billing.planUpdate" | "billing.automatedPlanUpdate" | "appDistribution.newTesterIosDevice" | "appDistribution.inAppFeedback" | "performance.threshold" | string;
35
35
  /**
36
36
  * Configuration for Firebase Alert functions.
37
37
  */
@@ -47,7 +47,7 @@ export interface FirebaseAlertOptions extends options.EventHandlerOptions {
47
47
  /**
48
48
  * Region where functions should be deployed.
49
49
  */
50
- region?: options.SupportedRegion | string;
50
+ region?: options.SupportedRegion | string | Expression<string> | ResetValue;
51
51
  /**
52
52
  * Amount of memory to allocate to a function.
53
53
  * A value of null restores the defaults of 256MB.
@@ -107,7 +107,7 @@ export interface FirebaseAlertOptions extends options.EventHandlerOptions {
107
107
  * Specific service account for the function to run as.
108
108
  * A value of null restores the default service account.
109
109
  */
110
- serviceAccount?: string | ResetValue;
110
+ serviceAccount?: string | Expression<string> | ResetValue;
111
111
  /**
112
112
  * Ingress settings which control where this function can be called from.
113
113
  * A value of null turns off ingress settings.
@@ -70,7 +70,7 @@ export interface AppDistributionOptions extends options.EventHandlerOptions {
70
70
  /**
71
71
  * Region where functions should be deployed.
72
72
  */
73
- region?: options.SupportedRegion | string;
73
+ region?: options.SupportedRegion | string | Expression<string> | ResetValue;
74
74
  /**
75
75
  * Amount of memory to allocate to a function.
76
76
  */
@@ -131,7 +131,7 @@ export interface AppDistributionOptions extends options.EventHandlerOptions {
131
131
  /**
132
132
  * Specific service account for the function to run as.
133
133
  */
134
- serviceAccount?: string | ResetValue;
134
+ serviceAccount?: string | Expression<string> | ResetValue;
135
135
  /**
136
136
  * Ingress settings which control where this function can be called from.
137
137
  */
@@ -136,7 +136,7 @@ export interface CrashlyticsOptions extends options.EventHandlerOptions {
136
136
  /**
137
137
  * Region where functions should be deployed.
138
138
  */
139
- region?: options.SupportedRegion | string;
139
+ region?: options.SupportedRegion | string | Expression<string> | ResetValue;
140
140
  /**
141
141
  * Amount of memory to allocate to a function.
142
142
  */
@@ -197,7 +197,7 @@ export interface CrashlyticsOptions extends options.EventHandlerOptions {
197
197
  /**
198
198
  * Specific service account for the function to run as.
199
199
  */
200
- serviceAccount?: string | ResetValue;
200
+ serviceAccount?: string | Expression<string> | ResetValue;
201
201
  /**
202
202
  * Ingress settings which control where this function can be called from.
203
203
  */
@@ -58,7 +58,7 @@ export interface ReferenceOptions<Ref extends string = string> extends options.E
58
58
  /**
59
59
  * Region where functions should be deployed.
60
60
  */
61
- region?: options.SupportedRegion | string;
61
+ region?: options.SupportedRegion | string | Expression<string> | ResetValue;
62
62
  /**
63
63
  * Amount of memory to allocate to a function.
64
64
  */
@@ -71,7 +71,7 @@ export interface ReferenceOptions<Ref extends string = string> extends options.E
71
71
  * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
72
72
  * function depends on the type of function: Event handling functions have a
73
73
  * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
74
- * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
74
+ * maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
75
75
  * timeout of 1,800s (30 minutes)
76
76
  */
77
77
  timeoutSeconds?: number | Expression<number> | ResetValue;
@@ -119,7 +119,7 @@ export interface ReferenceOptions<Ref extends string = string> extends options.E
119
119
  /**
120
120
  * Specific service account for the function to run as.
121
121
  */
122
- serviceAccount?: string | ResetValue;
122
+ serviceAccount?: string | Expression<string> | ResetValue;
123
123
  /**
124
124
  * Ingress settings which control where this function can be called from.
125
125
  */
@@ -35,7 +35,7 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions {
35
35
  /**
36
36
  * Region where functions should be deployed.
37
37
  */
38
- region?: options.SupportedRegion | string;
38
+ region?: options.SupportedRegion | string | Expression<string> | ResetValue;
39
39
  /**
40
40
  * Amount of memory to allocate to a function.
41
41
  */
@@ -96,7 +96,7 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions {
96
96
  /**
97
97
  * Specific service account for the function to run as.
98
98
  */
99
- serviceAccount?: string | ResetValue;
99
+ serviceAccount?: string | Expression<string> | ResetValue;
100
100
  /**
101
101
  * Ingress settings which control where this function can be called from.
102
102
  */
@@ -0,0 +1,92 @@
1
+ import * as firestore from "firebase-admin/firestore";
2
+ import { ParamsOf } from "../../common/params";
3
+ import { Change, CloudEvent, CloudFunction } from "../core";
4
+ import { EventHandlerOptions } from "../options";
5
+ export { Change };
6
+ /** A Firestore DocumentSnapshot */
7
+ export type DocumentSnapshot = firestore.DocumentSnapshot;
8
+ /** A Firestore QueryDocumentSnapshot */
9
+ export type QueryDocumentSnapshot = firestore.QueryDocumentSnapshot;
10
+ /** A CloudEvent that contains a DocumentSnapshot or a Change<DocumentSnapshot> */
11
+ export interface FirestoreEvent<T, Params = Record<string, string>> extends CloudEvent<T> {
12
+ /** The location of the Firestore instance */
13
+ location: string;
14
+ /** The project identifier */
15
+ project: string;
16
+ /** The Firestore database */
17
+ database: string;
18
+ /** The Firestore namespace */
19
+ namespace: string;
20
+ /** The document path */
21
+ document: string;
22
+ /**
23
+ * An object containing the values of the path patterns.
24
+ * Only named capture groups will be populated - {key}, {key=*}, {key=**}
25
+ */
26
+ params: Params;
27
+ }
28
+ /** DocumentOptions extend EventHandlerOptions with provided document and optional database and namespace. */
29
+ export interface DocumentOptions<Document extends string = string> extends EventHandlerOptions {
30
+ /** The document path */
31
+ document: Document;
32
+ /** The Firestore database */
33
+ database?: string;
34
+ /** The Firestore namespace */
35
+ namespace?: string;
36
+ }
37
+ /**
38
+ * Event handler which triggers when a document is created, updated, or deleted in Firestore.
39
+ *
40
+ * @param document - The Firestore document path to trigger on.
41
+ * @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
42
+ */
43
+ export declare function onDocumentWritten<Document extends string>(document: Document, handler: (event: FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>>;
44
+ /**
45
+ * Event handler which triggers when a document is created, updated, or deleted in Firestore.
46
+ *
47
+ * @param opts - Options that can be set on an individual event-handling function.
48
+ * @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
49
+ */
50
+ export declare function onDocumentWritten<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>>;
51
+ /**
52
+ * Event handler which triggers when a document is created in Firestore.
53
+ *
54
+ * @param document - The Firestore document path to trigger on.
55
+ * @param handler - Event handler which is run every time a Firestore create occurs.
56
+ */
57
+ export declare function onDocumentCreated<Document extends string>(document: Document, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
58
+ /**
59
+ * Event handler which triggers when a document is created in Firestore.
60
+ *
61
+ * @param opts - Options that can be set on an individual event-handling function.
62
+ * @param handler - Event handler which is run every time a Firestore create occurs.
63
+ */
64
+ export declare function onDocumentCreated<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
65
+ /**
66
+ * Event handler which triggers when a document is updated in Firestore.
67
+ *
68
+ * @param document - The Firestore document path to trigger on.
69
+ * @param handler - Event handler which is run every time a Firestore update occurs.
70
+ */
71
+ export declare function onDocumentUpdated<Document extends string>(document: Document, handler: (event: FirestoreEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>>;
72
+ /**
73
+ * Event handler which triggers when a document is updated in Firestore.
74
+ *
75
+ * @param opts - Options that can be set on an individual event-handling function.
76
+ * @param handler - Event handler which is run every time a Firestore update occurs.
77
+ */
78
+ export declare function onDocumentUpdated<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>>;
79
+ /**
80
+ * Event handler which triggers when a document is deleted in Firestore.
81
+ *
82
+ * @param document - The Firestore document path to trigger on.
83
+ * @param handler - Event handler which is run every time a Firestore delete occurs.
84
+ */
85
+ export declare function onDocumentDeleted<Document extends string>(document: Document, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
86
+ /**
87
+ * Event handler which triggers when a document is deleted in Firestore.
88
+ *
89
+ * @param opts - Options that can be set on an individual event-handling function.
90
+ * @param handler - Event handler which is run every time a Firestore delete occurs.
91
+ */
92
+ export declare function onDocumentDeleted<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ // The MIT License (MIT)
3
+ //
4
+ // Copyright (c) 2023 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.onChangedOperation = exports.onOperation = exports.makeEndpoint = exports.makeChangedFirestoreEvent = exports.makeFirestoreEvent = exports.makeParams = exports.createBeforeSnapshot = exports.createSnapshot = exports.getOpts = exports.onDocumentDeleted = exports.onDocumentUpdated = exports.onDocumentCreated = exports.onDocumentWritten = exports.deletedEventType = exports.updatedEventType = exports.createdEventType = exports.writtenEventType = exports.Change = void 0;
25
+ const logger = require("../../logger");
26
+ const path_1 = require("../../common/utilities/path");
27
+ const path_pattern_1 = require("../../common/utilities/path-pattern");
28
+ const manifest_1 = require("../../runtime/manifest");
29
+ const core_1 = require("../core");
30
+ Object.defineProperty(exports, "Change", { enumerable: true, get: function () { return core_1.Change; } });
31
+ const options_1 = require("../options");
32
+ const firestore_1 = require("../../common/providers/firestore");
33
+ /** @internal */
34
+ exports.writtenEventType = "google.cloud.firestore.document.v1.written";
35
+ /** @internal */
36
+ exports.createdEventType = "google.cloud.firestore.document.v1.created";
37
+ /** @internal */
38
+ exports.updatedEventType = "google.cloud.firestore.document.v1.updated";
39
+ /** @internal */
40
+ exports.deletedEventType = "google.cloud.firestore.document.v1.deleted";
41
+ /**
42
+ * Event handler which triggers when a document is created, updated, or deleted in Firestore.
43
+ *
44
+ * @param documentOrOpts - Options or a string document path.
45
+ * @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
46
+ */
47
+ function onDocumentWritten(documentOrOpts, handler) {
48
+ return onChangedOperation(exports.writtenEventType, documentOrOpts, handler);
49
+ }
50
+ exports.onDocumentWritten = onDocumentWritten;
51
+ /**
52
+ * Event handler which triggers when a document is created in Firestore.
53
+ *
54
+ * @param documentOrOpts - Options or a string document path.
55
+ * @param handler - Event handler which is run every time a Firestore create occurs.
56
+ */
57
+ function onDocumentCreated(documentOrOpts, handler) {
58
+ return onOperation(exports.createdEventType, documentOrOpts, handler);
59
+ }
60
+ exports.onDocumentCreated = onDocumentCreated;
61
+ /**
62
+ * Event handler which triggers when a document is updated in Firestore.
63
+ *
64
+ * @param documentOrOpts - Options or a string document path.
65
+ * @param handler - Event handler which is run every time a Firestore update occurs.
66
+ */
67
+ function onDocumentUpdated(documentOrOpts, handler) {
68
+ return onChangedOperation(exports.updatedEventType, documentOrOpts, handler);
69
+ }
70
+ exports.onDocumentUpdated = onDocumentUpdated;
71
+ /**
72
+ * Event handler which triggers when a document is deleted in Firestore.
73
+ *
74
+ * @param documentOrOpts - Options or a string document path.
75
+ * @param handler - Event handler which is run every time a Firestore delete occurs.
76
+ */
77
+ function onDocumentDeleted(documentOrOpts, handler) {
78
+ return onOperation(exports.deletedEventType, documentOrOpts, handler);
79
+ }
80
+ exports.onDocumentDeleted = onDocumentDeleted;
81
+ /** @internal */
82
+ function getOpts(documentOrOpts) {
83
+ let document;
84
+ let database;
85
+ let namespace;
86
+ let opts;
87
+ if (typeof documentOrOpts === "string") {
88
+ document = (0, path_1.normalizePath)(documentOrOpts);
89
+ database = "(default)";
90
+ namespace = "(default)";
91
+ opts = {};
92
+ }
93
+ else {
94
+ document = (0, path_1.normalizePath)(documentOrOpts.document);
95
+ database = documentOrOpts.database || "(default)";
96
+ namespace = documentOrOpts.namespace || "(default)";
97
+ opts = { ...documentOrOpts };
98
+ delete opts.document;
99
+ delete opts.database;
100
+ delete opts.namespace;
101
+ }
102
+ return {
103
+ document,
104
+ database,
105
+ namespace,
106
+ opts,
107
+ };
108
+ }
109
+ exports.getOpts = getOpts;
110
+ /** @hidden */
111
+ function getPath(event) {
112
+ return `projects/${event.project}/databases/${event.database}/documents/${event.document}`;
113
+ }
114
+ /** @internal */
115
+ function createSnapshot(event) {
116
+ var _a, _b, _c, _d;
117
+ if (((_a = event.datacontenttype) === null || _a === void 0 ? void 0 : _a.includes("application/protobuf")) || Buffer.isBuffer(event.data)) {
118
+ return (0, firestore_1.createSnapshotFromProtobuf)(event.data, getPath(event));
119
+ }
120
+ else if ((_b = event.datacontenttype) === null || _b === void 0 ? void 0 : _b.includes("application/json")) {
121
+ return (0, firestore_1.createSnapshotFromJson)(event.data, event.source, (_c = event.data.value) === null || _c === void 0 ? void 0 : _c.createTime, (_d = event.data.value) === null || _d === void 0 ? void 0 : _d.updateTime);
122
+ }
123
+ else {
124
+ logger.error(`Cannot determine payload type, datacontenttype is ${event.datacontenttype}, failing out.`);
125
+ throw Error("Error: Cannot parse event payload.");
126
+ }
127
+ }
128
+ exports.createSnapshot = createSnapshot;
129
+ /** @internal */
130
+ function createBeforeSnapshot(event) {
131
+ var _a, _b, _c, _d;
132
+ if (((_a = event.datacontenttype) === null || _a === void 0 ? void 0 : _a.includes("application/protobuf")) || Buffer.isBuffer(event.data)) {
133
+ return (0, firestore_1.createBeforeSnapshotFromProtobuf)(event.data, getPath(event));
134
+ }
135
+ else if ((_b = event.datacontenttype) === null || _b === void 0 ? void 0 : _b.includes("application/json")) {
136
+ return (0, firestore_1.createBeforeSnapshotFromJson)(event.data, event.source, (_c = event.data.oldValue) === null || _c === void 0 ? void 0 : _c.createTime, (_d = event.data.oldValue) === null || _d === void 0 ? void 0 : _d.updateTime);
137
+ }
138
+ else {
139
+ logger.error(`Cannot determine payload type, datacontenttype is ${event.datacontenttype}, failing out.`);
140
+ throw Error("Error: Cannot parse event payload.");
141
+ }
142
+ }
143
+ exports.createBeforeSnapshot = createBeforeSnapshot;
144
+ /** @internal */
145
+ function makeParams(document, documentPattern) {
146
+ return {
147
+ ...documentPattern.extractMatches(document),
148
+ };
149
+ }
150
+ exports.makeParams = makeParams;
151
+ /** @internal */
152
+ function makeFirestoreEvent(eventType, event, params) {
153
+ const data = event.data
154
+ ? eventType === exports.createdEventType
155
+ ? createSnapshot(event)
156
+ : createBeforeSnapshot(event)
157
+ : undefined;
158
+ const firestoreEvent = {
159
+ ...event,
160
+ params,
161
+ data,
162
+ };
163
+ delete firestoreEvent.datacontenttype;
164
+ delete firestoreEvent.dataschema;
165
+ return firestoreEvent;
166
+ }
167
+ exports.makeFirestoreEvent = makeFirestoreEvent;
168
+ /** @internal */
169
+ function makeChangedFirestoreEvent(event, params) {
170
+ const data = event.data
171
+ ? core_1.Change.fromObjects(createBeforeSnapshot(event), createSnapshot(event))
172
+ : undefined;
173
+ const firestoreEvent = {
174
+ ...event,
175
+ params,
176
+ data,
177
+ };
178
+ delete firestoreEvent.datacontenttype;
179
+ delete firestoreEvent.dataschema;
180
+ return firestoreEvent;
181
+ }
182
+ exports.makeChangedFirestoreEvent = makeChangedFirestoreEvent;
183
+ /** @internal */
184
+ function makeEndpoint(eventType, opts, document, database, namespace) {
185
+ const baseOpts = (0, options_1.optionsToEndpoint)((0, options_1.getGlobalOptions)());
186
+ const specificOpts = (0, options_1.optionsToEndpoint)(opts);
187
+ const eventFilters = {
188
+ database,
189
+ namespace,
190
+ };
191
+ const eventFilterPathPatterns = {};
192
+ document.hasWildcards()
193
+ ? (eventFilterPathPatterns.document = document.getValue())
194
+ : (eventFilters.document = document.getValue());
195
+ return {
196
+ ...(0, manifest_1.initV2Endpoint)((0, options_1.getGlobalOptions)(), opts),
197
+ platform: "gcfv2",
198
+ ...baseOpts,
199
+ ...specificOpts,
200
+ labels: {
201
+ ...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
202
+ ...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
203
+ },
204
+ eventTrigger: {
205
+ eventType,
206
+ eventFilters,
207
+ eventFilterPathPatterns,
208
+ retry: !!opts.retry,
209
+ },
210
+ };
211
+ }
212
+ exports.makeEndpoint = makeEndpoint;
213
+ /** @internal */
214
+ function onOperation(eventType, documentOrOpts, handler) {
215
+ const { document, database, namespace, opts } = getOpts(documentOrOpts);
216
+ const documentPattern = new path_pattern_1.PathPattern(document);
217
+ // wrap the handler
218
+ const func = (raw) => {
219
+ const event = raw;
220
+ const params = makeParams(event.document, documentPattern);
221
+ const firestoreEvent = makeFirestoreEvent(eventType, event, params);
222
+ return handler(firestoreEvent);
223
+ };
224
+ func.run = handler;
225
+ func.__endpoint = makeEndpoint(eventType, opts, documentPattern, database, namespace);
226
+ return func;
227
+ }
228
+ exports.onOperation = onOperation;
229
+ /** @internal */
230
+ function onChangedOperation(eventType, documentOrOpts, handler) {
231
+ const { document, database, namespace, opts } = getOpts(documentOrOpts);
232
+ const documentPattern = new path_pattern_1.PathPattern(document);
233
+ // wrap the handler
234
+ const func = (raw) => {
235
+ const event = raw;
236
+ const params = makeParams(event.document, documentPattern);
237
+ const firestoreEvent = makeChangedFirestoreEvent(event, params);
238
+ return handler(firestoreEvent);
239
+ };
240
+ func.run = handler;
241
+ func.__endpoint = makeEndpoint(eventType, opts, documentPattern, database, namespace);
242
+ return func;
243
+ }
244
+ exports.onChangedOperation = onChangedOperation;
@@ -16,7 +16,7 @@ export interface HttpsOptions extends Omit<GlobalOptions, "region"> {
16
16
  */
17
17
  omit?: boolean | Expression<boolean>;
18
18
  /** HTTP functions can override global options and can specify multiple regions to deploy to. */
19
- region?: SupportedRegion | string | Array<SupportedRegion | string>;
19
+ region?: SupportedRegion | string | Array<SupportedRegion | string> | Expression<string> | ResetValue;
20
20
  /** If true, allows CORS on requests to this function.
21
21
  * If this is a `string` or `RegExp`, allows requests from domains that match the provided value.
22
22
  * If this is an `Array`, allows requests from domains matching at least one entry of the array.
@@ -83,7 +83,7 @@ export interface HttpsOptions extends Omit<GlobalOptions, "region"> {
83
83
  /**
84
84
  * Specific service account for the function to run as.
85
85
  */
86
- serviceAccount?: string | ResetValue;
86
+ serviceAccount?: string | Expression<string> | ResetValue;
87
87
  /**
88
88
  * Ingress settings which control where this function can be called from.
89
89
  */
@@ -113,7 +113,7 @@ export interface CallableOptions extends HttpsOptions {
113
113
  /**
114
114
  * Handles HTTPS requests.
115
115
  */
116
- export declare type HttpsFunction = ((
116
+ export type HttpsFunction = ((
117
117
  /** An Express request object representing the HTTPS call to the function. */
118
118
  req: Request,
119
119
  /** An Express response object, for this function to respond to callers. */
@@ -33,7 +33,7 @@ export interface BlockingOptions {
33
33
  /**
34
34
  * Region where functions should be deployed.
35
35
  */
36
- region?: options.SupportedRegion | string;
36
+ region?: options.SupportedRegion | string | Expression<string> | ResetValue;
37
37
  /**
38
38
  * Amount of memory to allocate to a function.
39
39
  */
@@ -94,7 +94,7 @@ export interface BlockingOptions {
94
94
  /**
95
95
  * Specific service account for the function to run as.
96
96
  */
97
- serviceAccount?: string | ResetValue;
97
+ serviceAccount?: string | Expression<string> | ResetValue;
98
98
  /**
99
99
  * Ingress settings which control where this function can be called from.
100
100
  */
@@ -91,7 +91,7 @@ export interface PubSubOptions extends options.EventHandlerOptions {
91
91
  /**
92
92
  * Region where functions should be deployed.
93
93
  */
94
- region?: options.SupportedRegion | string;
94
+ region?: options.SupportedRegion | string | Expression<string> | ResetValue;
95
95
  /**
96
96
  * Amount of memory to allocate to a function.
97
97
  */
@@ -152,7 +152,7 @@ export interface PubSubOptions extends options.EventHandlerOptions {
152
152
  /**
153
153
  * Specific service account for the function to run as.
154
154
  */
155
- serviceAccount?: string | ResetValue;
155
+ serviceAccount?: string | Expression<string> | ResetValue;
156
156
  /**
157
157
  * Ingress settings which control where this function can be called from.
158
158
  */
@@ -10,7 +10,7 @@ export interface ConfigUser {
10
10
  imageUrl: string;
11
11
  }
12
12
  /** What type of update was associated with the Remote Config template version. */
13
- export declare type ConfigUpdateOrigin =
13
+ export type ConfigUpdateOrigin =
14
14
  /** Catch-all for unrecognized values. */
15
15
  "REMOTE_CONFIG_UPDATE_ORIGIN_UNSPECIFIED"
16
16
  /** The update came from the Firebase UI. */
@@ -20,7 +20,7 @@ export declare type ConfigUpdateOrigin =
20
20
  /** The update came from the Firebase Admin Node SDK. */
21
21
  | "ADMIN_SDK_NODE";
22
22
  /** Where the Remote Config update action originated. */
23
- export declare type ConfigUpdateType =
23
+ export type ConfigUpdateType =
24
24
  /** Catch-all for unrecognized enum values */
25
25
  "REMOTE_CONFIG_UPDATE_TYPE_UNSPECIFIED"
26
26
  /** A regular incremental update */
@@ -167,7 +167,7 @@ export interface StorageOptions extends options.EventHandlerOptions {
167
167
  /**
168
168
  * Region where functions should be deployed.
169
169
  */
170
- region?: options.SupportedRegion | string;
170
+ region?: options.SupportedRegion | string | Expression<string> | ResetValue;
171
171
  /**
172
172
  * Amount of memory to allocate to a function.
173
173
  */
@@ -228,7 +228,7 @@ export interface StorageOptions extends options.EventHandlerOptions {
228
228
  /**
229
229
  * Specific service account for the function to run as.
230
230
  */
231
- serviceAccount?: string | ResetValue;
231
+ serviceAccount?: string | Expression<string> | ResetValue;
232
232
  /**
233
233
  * Ingress settings which control where this function can be called from.
234
234
  */
@@ -4,7 +4,7 @@ import * as options from "../options";
4
4
  import { HttpsFunction } from "./https";
5
5
  import { Expression } from "../../params";
6
6
  import { SecretParam } from "../../params/types";
7
- export { AuthData, Request };
7
+ export { AuthData, Request, RateLimits, RetryConfig };
8
8
  export interface TaskQueueOptions extends options.EventHandlerOptions {
9
9
  /** How a task should be retried in the event of a non-2xx return. */
10
10
  retryConfig?: RetryConfig;
@@ -26,7 +26,7 @@ export interface TaskQueueOptions extends options.EventHandlerOptions {
26
26
  /**
27
27
  * Region where functions should be deployed.
28
28
  */
29
- region?: options.SupportedRegion | string;
29
+ region?: options.SupportedRegion | string | Expression<string> | ResetValue;
30
30
  /**
31
31
  * Amount of memory to allocate to a function.
32
32
  */
@@ -87,7 +87,7 @@ export interface TaskQueueOptions extends options.EventHandlerOptions {
87
87
  /**
88
88
  * Specific service account for the function to run as.
89
89
  */
90
- serviceAccount?: string | ResetValue;
90
+ serviceAccount?: string | Expression<string> | ResetValue;
91
91
  /**
92
92
  * Ingress settings which control where this function can be called from.
93
93
  */
@@ -1,7 +1,7 @@
1
1
  import { CloudEvent, CloudFunction } from "../core";
2
2
  import { EventHandlerOptions } from "../options";
3
3
  /** Possible test states for a test matrix. */
4
- export declare type TestState =
4
+ export type TestState =
5
5
  /** The default value. This value is used if the state is omitted. */
6
6
  "TEST_STATE_UNSPECIFIED"
7
7
  /** The test matrix is being validated. */
@@ -15,7 +15,7 @@ export declare type TestState =
15
15
  /** The test matrix was not run because the provided inputs are not valid. */
16
16
  | "INVALID";
17
17
  /** Outcome summary for a finished test matrix. */
18
- export declare type OutcomeSummary =
18
+ export type OutcomeSummary =
19
19
  /** The default value. This value is used if the state is omitted. */
20
20
  "OUTCOME_SUMMARY_UNSPECIFIED"
21
21
  /**
package/lib/v2/trace.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { CloudEvent } from "./core";
2
- declare type CloudEventFunction<T> = (raw: CloudEvent<T>) => any | Promise<any>;
2
+ type CloudEventFunction<T> = (raw: CloudEvent<T>) => any | Promise<any>;
3
3
  export declare function wrapTraceContext<T>(handler: CloudEventFunction<T>): CloudEventFunction<T>;
4
4
  export {};