firebase-functions 3.24.0 → 4.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 (130) hide show
  1. package/README.md +7 -9
  2. package/lib/bin/firebase-functions.js +13 -15
  3. package/lib/common/app.d.ts +14 -0
  4. package/lib/common/app.js +62 -0
  5. package/lib/common/change.d.ts +0 -5
  6. package/lib/common/change.js +5 -7
  7. package/lib/common/config.d.ts +6 -0
  8. package/lib/common/config.js +49 -0
  9. package/lib/common/debug.js +2 -2
  10. package/lib/common/encoding.d.ts +0 -8
  11. package/lib/common/encoding.js +6 -29
  12. package/lib/common/options.d.ts +14 -0
  13. package/lib/common/options.js +44 -0
  14. package/lib/common/params.d.ts +32 -0
  15. package/lib/common/params.js +23 -0
  16. package/lib/common/providers/database.d.ts +17 -19
  17. package/lib/common/providers/database.js +68 -39
  18. package/lib/common/providers/https.d.ts +11 -52
  19. package/lib/common/providers/https.js +115 -110
  20. package/lib/common/providers/identity.d.ts +8 -8
  21. package/lib/common/providers/identity.js +71 -79
  22. package/lib/common/providers/tasks.d.ts +11 -10
  23. package/lib/common/providers/tasks.js +10 -9
  24. package/lib/common/timezone.js +538 -538
  25. package/lib/common/trace.d.ts +14 -0
  26. package/lib/common/trace.js +69 -0
  27. package/lib/{encoder.d.ts → common/utilities/encoder.d.ts} +0 -0
  28. package/lib/{encoder.js → common/utilities/encoder.js} +1 -1
  29. package/lib/{utilities → common/utilities}/path-pattern.d.ts +0 -0
  30. package/lib/{utilities → common/utilities}/path-pattern.js +17 -16
  31. package/lib/{utilities → common/utilities}/path.d.ts +0 -0
  32. package/lib/{utilities → common/utilities}/path.js +5 -7
  33. package/lib/{utils.d.ts → common/utilities/utils.d.ts} +1 -1
  34. package/lib/{utils.js → common/utilities/utils.js} +18 -12
  35. package/lib/logger/common.d.ts +1 -3
  36. package/lib/logger/common.js +9 -14
  37. package/lib/logger/compat.js +9 -9
  38. package/lib/logger/index.d.ts +1 -1
  39. package/lib/logger/index.js +24 -30
  40. package/lib/{v2/params → params}/index.d.ts +22 -9
  41. package/lib/{v2/params → params}/index.js +22 -14
  42. package/lib/params/types.d.ts +180 -0
  43. package/lib/params/types.js +289 -0
  44. package/lib/runtime/loader.js +12 -14
  45. package/lib/runtime/manifest.d.ts +56 -24
  46. package/lib/runtime/manifest.js +114 -4
  47. package/lib/v1/cloud-functions.d.ts +232 -0
  48. package/lib/v1/cloud-functions.js +205 -0
  49. package/lib/v1/config.d.ts +8 -0
  50. package/lib/v1/config.js +75 -0
  51. package/lib/{function-builder.d.ts → v1/function-builder.d.ts} +16 -16
  52. package/lib/{function-builder.js → v1/function-builder.js} +56 -46
  53. package/lib/v1/function-configuration.d.ts +197 -0
  54. package/lib/v1/function-configuration.js +70 -0
  55. package/lib/v1/index.d.ts +20 -0
  56. package/lib/{index.js → v1/index.js} +5 -10
  57. package/lib/{providers → v1/providers}/analytics.d.ts +5 -11
  58. package/lib/{providers → v1/providers}/analytics.js +49 -43
  59. package/lib/{providers → v1/providers}/auth.d.ts +28 -18
  60. package/lib/{providers → v1/providers}/auth.js +45 -34
  61. package/lib/{providers → v1/providers}/database.d.ts +25 -42
  62. package/lib/{providers → v1/providers}/database.js +46 -46
  63. package/lib/{providers → v1/providers}/firestore.d.ts +15 -33
  64. package/lib/{providers → v1/providers}/firestore.js +40 -44
  65. package/lib/{providers → v1/providers}/https.d.ts +3 -8
  66. package/lib/{providers → v1/providers}/https.js +14 -22
  67. package/lib/{providers → v1/providers}/pubsub.d.ts +8 -16
  68. package/lib/{providers → v1/providers}/pubsub.js +22 -26
  69. package/lib/{providers → v1/providers}/remoteConfig.d.ts +2 -11
  70. package/lib/{providers → v1/providers}/remoteConfig.js +9 -9
  71. package/lib/{providers → v1/providers}/storage.d.ts +11 -26
  72. package/lib/{providers → v1/providers}/storage.js +24 -29
  73. package/lib/{providers → v1/providers}/tasks.d.ts +6 -8
  74. package/lib/{providers → v1/providers}/tasks.js +12 -17
  75. package/lib/{providers → v1/providers}/testLab.d.ts +86 -46
  76. package/lib/{providers → v1/providers}/testLab.js +14 -14
  77. package/lib/v2/core.d.ts +4 -5
  78. package/lib/v2/index.d.ts +16 -14
  79. package/lib/v2/index.js +5 -1
  80. package/lib/v2/options.d.ts +52 -32
  81. package/lib/v2/options.js +32 -47
  82. package/lib/v2/providers/alerts/alerts.d.ts +20 -18
  83. package/lib/v2/providers/alerts/alerts.js +9 -6
  84. package/lib/v2/providers/alerts/appDistribution.d.ts +36 -26
  85. package/lib/v2/providers/alerts/appDistribution.js +10 -7
  86. package/lib/v2/providers/alerts/billing.d.ts +5 -5
  87. package/lib/v2/providers/alerts/billing.js +5 -4
  88. package/lib/v2/providers/alerts/crashlytics.d.ts +32 -30
  89. package/lib/v2/providers/alerts/crashlytics.js +10 -9
  90. package/lib/v2/providers/alerts/index.d.ts +5 -5
  91. package/lib/v2/providers/alerts/performance.d.ts +15 -3
  92. package/lib/v2/providers/alerts/performance.js +5 -7
  93. package/lib/v2/providers/database.d.ts +41 -38
  94. package/lib/v2/providers/database.js +22 -17
  95. package/lib/v2/providers/eventarc.d.ts +25 -23
  96. package/lib/v2/providers/eventarc.js +10 -7
  97. package/lib/v2/providers/https.d.ts +43 -33
  98. package/lib/v2/providers/https.js +18 -56
  99. package/lib/v2/providers/identity.d.ts +25 -23
  100. package/lib/v2/providers/identity.js +10 -7
  101. package/lib/v2/providers/pubsub.d.ts +25 -23
  102. package/lib/v2/providers/pubsub.js +11 -27
  103. package/lib/v2/providers/remoteConfig.d.ts +63 -0
  104. package/lib/v2/providers/remoteConfig.js +65 -0
  105. package/lib/v2/providers/scheduler.d.ts +14 -12
  106. package/lib/v2/providers/scheduler.js +16 -14
  107. package/lib/v2/providers/storage.d.ts +32 -30
  108. package/lib/v2/providers/storage.js +16 -32
  109. package/lib/v2/providers/tasks.d.ts +30 -26
  110. package/lib/v2/providers/tasks.js +14 -31
  111. package/lib/v2/providers/testLab.d.ts +110 -0
  112. package/lib/v2/providers/testLab.js +65 -0
  113. package/lib/v2/trace.d.ts +4 -0
  114. package/lib/v2/trace.js +21 -0
  115. package/package.json +62 -67
  116. package/lib/apps.d.ts +0 -35
  117. package/lib/apps.js +0 -112
  118. package/lib/cloud-functions.d.ts +0 -231
  119. package/lib/cloud-functions.js +0 -251
  120. package/lib/config.d.ts +0 -24
  121. package/lib/config.js +0 -117
  122. package/lib/function-configuration.d.ts +0 -108
  123. package/lib/function-configuration.js +0 -71
  124. package/lib/handler-builder.d.ts +0 -256
  125. package/lib/handler-builder.js +0 -349
  126. package/lib/index.d.ts +0 -19
  127. package/lib/setup.d.ts +0 -1
  128. package/lib/setup.js +0 -60
  129. package/lib/v2/params/types.d.ts +0 -118
  130. package/lib/v2/params/types.js +0 -196
@@ -22,19 +22,20 @@
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.getOptsAndApp = exports.onOperation = exports.onNewAnrIssuePublished = exports.onVelocityAlertPublished = exports.onStabilityDigestPublished = exports.onRegressionAlertPublished = exports.onNewNonfatalIssuePublished = exports.onNewFatalIssuePublished = exports.newAnrIssueAlert = exports.velocityAlert = exports.stabilityDigestAlert = exports.regressionAlert = exports.newNonfatalIssueAlert = exports.newFatalIssueAlert = void 0;
25
+ const trace_1 = require("../../trace");
25
26
  const alerts_1 = require("./alerts");
26
27
  /** @internal */
27
- exports.newFatalIssueAlert = 'crashlytics.newFatalIssue';
28
+ exports.newFatalIssueAlert = "crashlytics.newFatalIssue";
28
29
  /** @internal */
29
- exports.newNonfatalIssueAlert = 'crashlytics.newNonfatalIssue';
30
+ exports.newNonfatalIssueAlert = "crashlytics.newNonfatalIssue";
30
31
  /** @internal */
31
- exports.regressionAlert = 'crashlytics.regression';
32
+ exports.regressionAlert = "crashlytics.regression";
32
33
  /** @internal */
33
- exports.stabilityDigestAlert = 'crashlytics.stabilityDigest';
34
+ exports.stabilityDigestAlert = "crashlytics.stabilityDigest";
34
35
  /** @internal */
35
- exports.velocityAlert = 'crashlytics.velocity';
36
+ exports.velocityAlert = "crashlytics.velocity";
36
37
  /** @internal */
37
- exports.newAnrIssueAlert = 'crashlytics.newAnrIssue';
38
+ exports.newAnrIssueAlert = "crashlytics.newAnrIssue";
38
39
  /**
39
40
  * Declares a function that can handle a new fatal issue published to Crashlytics.
40
41
  * @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
@@ -97,13 +98,13 @@ function onNewAnrIssuePublished(appIdOrOptsOrHandler, handler) {
97
98
  exports.onNewAnrIssuePublished = onNewAnrIssuePublished;
98
99
  /** @internal */
99
100
  function onOperation(alertType, appIdOrOptsOrHandler, handler) {
100
- if (typeof appIdOrOptsOrHandler === 'function') {
101
+ if (typeof appIdOrOptsOrHandler === "function") {
101
102
  handler = appIdOrOptsOrHandler;
102
103
  appIdOrOptsOrHandler = {};
103
104
  }
104
105
  const [opts, appId] = getOptsAndApp(appIdOrOptsOrHandler);
105
106
  const func = (raw) => {
106
- return handler((0, alerts_1.convertAlertAndApp)(raw));
107
+ return (0, trace_1.wrapTraceContext)(handler((0, alerts_1.convertAlertAndApp)(raw)));
107
108
  };
108
109
  func.run = handler;
109
110
  func.__endpoint = (0, alerts_1.getEndpointAnnotation)(opts, alertType, appId);
@@ -117,7 +118,7 @@ exports.onOperation = onOperation;
117
118
  function getOptsAndApp(appIdOrOpts) {
118
119
  let opts;
119
120
  let appId;
120
- if (typeof appIdOrOpts === 'string') {
121
+ if (typeof appIdOrOpts === "string") {
121
122
  opts = {};
122
123
  appId = appIdOrOpts;
123
124
  }
@@ -4,9 +4,9 @@
4
4
  * notify users via Firebase Alerts.
5
5
  * @packageDocumentation
6
6
  */
7
- import * as appDistribution from './appDistribution';
8
- import * as billing from './billing';
9
- import * as crashlytics from './crashlytics';
10
- import * as performance from './performance';
7
+ import * as appDistribution from "./appDistribution";
8
+ import * as billing from "./billing";
9
+ import * as crashlytics from "./crashlytics";
10
+ import * as performance from "./performance";
11
11
  export { appDistribution, billing, crashlytics, performance };
12
- export * from './alerts';
12
+ export * from "./alerts";
@@ -2,24 +2,35 @@
2
2
  * Cloud functions to handle Firebase Performance Monitoring events from Firebase Alerts.
3
3
  * @packageDocumentation
4
4
  */
5
- import { CloudEvent, CloudFunction } from '../../core';
6
- import { EventHandlerOptions } from '../../options';
7
- import { FirebaseAlertData } from './alerts';
5
+ import { CloudEvent, CloudFunction } from "../../core";
6
+ import { EventHandlerOptions } from "../../options";
7
+ import { FirebaseAlertData } from "./alerts";
8
8
  /**
9
9
  * The internal payload object for a performance threshold alert.
10
10
  * Payload is wrapped inside a {@link FirebaseAlertData} object.
11
11
  */
12
12
  export interface ThresholdAlertPayload {
13
+ /** Name of the trace or network request this alert is for (e.g. my_custom_trace, firebase.com/api/123) */
13
14
  eventName: string;
15
+ /** The resource type this alert is for (i.e. trace, network request, screen rendering, etc.) */
14
16
  eventType: string;
17
+ /** The metric type this alert is for (i.e. success rate, response time, duration, etc.) */
15
18
  metricType: string;
19
+ /** The number of events checked for this alert condition */
16
20
  numSamples: number;
21
+ /** The threshold value of the alert condition without units (e.g. "75", "2.1") */
17
22
  thresholdValue: number;
23
+ /** The unit for the alert threshold (e.g. "percent", "seconds") */
18
24
  thresholdUnit: string;
25
+ /** The percentile of the alert condition, can be 0 if percentile is not applicable to the alert condition and omitted; range: [1, 100] */
19
26
  conditionPercentile?: number;
27
+ /** The app version this alert was triggered for, can be omitted if the alert is for a network request (because the alert was checked against data from all versions of app) or a web app (where the app is versionless) */
20
28
  appVersion?: string;
29
+ /** The value that violated the alert condition (e.g. "76.5", "3") */
21
30
  violationValue: number;
31
+ /** The unit for the violation value (e.g. "percent", "seconds") */
22
32
  violationUnit: string;
33
+ /** The link to Fireconsole to investigate more into this alert */
23
34
  investigateUri: string;
24
35
  }
25
36
  /**
@@ -36,6 +47,7 @@ export interface PerformanceEvent<T> extends CloudEvent<FirebaseAlertData<T>> {
36
47
  * Configuration for app distribution functions.
37
48
  */
38
49
  export interface PerformanceOptions extends EventHandlerOptions {
50
+ /** Scope the function to trigger on a specific application. */
39
51
  appId?: string;
40
52
  }
41
53
  /**
@@ -24,7 +24,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.convertPayload = exports.getOptsAndApp = exports.onThresholdAlertPublished = exports.thresholdAlert = void 0;
25
25
  const alerts_1 = require("./alerts");
26
26
  /** @internal */
27
- exports.thresholdAlert = 'performance.threshold';
27
+ exports.thresholdAlert = "performance.threshold";
28
28
  /**
29
29
  * Declares a function that can handle receiving performance threshold alerts.
30
30
  * @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
@@ -32,7 +32,7 @@ exports.thresholdAlert = 'performance.threshold';
32
32
  * @returns A function that you can export and deploy.
33
33
  */
34
34
  function onThresholdAlertPublished(appIdOrOptsOrHandler, handler) {
35
- if (typeof appIdOrOptsOrHandler === 'function') {
35
+ if (typeof appIdOrOptsOrHandler === "function") {
36
36
  handler = appIdOrOptsOrHandler;
37
37
  appIdOrOptsOrHandler = {};
38
38
  }
@@ -53,7 +53,7 @@ exports.onThresholdAlertPublished = onThresholdAlertPublished;
53
53
  * @internal
54
54
  */
55
55
  function getOptsAndApp(appIdOrOpts) {
56
- if (typeof appIdOrOpts === 'string') {
56
+ if (typeof appIdOrOpts === "string") {
57
57
  return [{}, appIdOrOpts];
58
58
  }
59
59
  const opts = { ...appIdOrOpts };
@@ -68,12 +68,10 @@ exports.getOptsAndApp = getOptsAndApp;
68
68
  */
69
69
  function convertPayload(raw) {
70
70
  const payload = { ...raw };
71
- if (typeof payload.conditionPercentile !== 'undefined' &&
72
- payload.conditionPercentile === 0) {
71
+ if (typeof payload.conditionPercentile !== "undefined" && payload.conditionPercentile === 0) {
73
72
  delete payload.conditionPercentile;
74
73
  }
75
- if (typeof payload.appVersion !== 'undefined' &&
76
- payload.appVersion.length === 0) {
74
+ if (typeof payload.appVersion !== "undefined" && payload.appVersion.length === 0) {
77
75
  delete payload.appVersion;
78
76
  }
79
77
  return payload;
@@ -1,12 +1,15 @@
1
- import { Change } from '../../common/change';
2
- import { DataSnapshot } from '../../common/providers/database';
3
- import { CloudEvent, CloudFunction } from '../core';
4
- import * as options from '../options';
5
- import { Expression } from '../params';
1
+ import { Change } from "../../common/change";
2
+ import { ParamsOf } from "../../common/params";
3
+ import { ResetValue } from "../../common/options";
4
+ import { DataSnapshot } from "../../common/providers/database";
5
+ import { CloudEvent, CloudFunction } from "../core";
6
+ import { Expression } from "../../params";
7
+ import * as options from "../options";
8
+ import { SecretParam } from "../../params/types";
6
9
  export { DataSnapshot };
7
10
  /** @hidden */
8
11
  export interface RawRTDBCloudEventData {
9
- ['@type']: 'type.googleapis.com/google.events.firebase.database.v1.ReferenceEventData';
12
+ ["@type"]: "type.googleapis.com/google.events.firebase.database.v1.ReferenceEventData";
10
13
  data: any;
11
14
  delta: any;
12
15
  }
@@ -18,7 +21,7 @@ export interface RawRTDBCloudEvent extends CloudEvent<RawRTDBCloudEventData> {
18
21
  location: string;
19
22
  }
20
23
  /** A CloudEvent that contains a DataSnapshot or a Change<DataSnapshot> */
21
- export interface DatabaseEvent<T> extends CloudEvent<T> {
24
+ export interface DatabaseEvent<T, Params = Record<string, string>> extends CloudEvent<T> {
22
25
  /** The domain of the database instance */
23
26
  firebaseDatabaseHost: string;
24
27
  /** The instance ID portion of the fully qualified resource name */
@@ -31,16 +34,16 @@ export interface DatabaseEvent<T> extends CloudEvent<T> {
31
34
  * An object containing the values of the path patterns.
32
35
  * Only named capture groups will be populated - {key}, {key=*}, {key=**}
33
36
  */
34
- params: Record<string, string>;
37
+ params: Params;
35
38
  }
36
39
  /** ReferenceOptions extend EventHandlerOptions with provided ref and optional instance */
37
- export interface ReferenceOptions extends options.EventHandlerOptions {
40
+ export interface ReferenceOptions<Ref extends string = string> extends options.EventHandlerOptions {
38
41
  /**
39
42
  * Specify the handler to trigger on a database reference(s).
40
43
  * This value can either be a single reference or a pattern.
41
44
  * Examples: '/foo/bar', '/foo/{bar}'
42
45
  */
43
- ref: string;
46
+ ref: Ref;
44
47
  /**
45
48
  * Specify the handler to trigger on a database instance(s).
46
49
  * If present, this value can either be a single instance or a pattern.
@@ -54,76 +57,76 @@ export interface ReferenceOptions extends options.EventHandlerOptions {
54
57
  region?: options.SupportedRegion | string;
55
58
  /**
56
59
  * Amount of memory to allocate to a function.
57
- * A value of null restores the defaults of 256MB.
58
60
  */
59
- memory?: options.MemoryOption | Expression<number> | null;
61
+ memory?: options.MemoryOption | Expression<number> | ResetValue;
60
62
  /**
61
63
  * Timeout for the function in sections, possible values are 0 to 540.
62
64
  * HTTPS functions can specify a higher timeout.
63
- * A value of null restores the default of 60s
65
+ *
66
+ * @remarks
64
67
  * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
65
68
  * function depends on the type of function: Event handling functions have a
66
69
  * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
67
70
  * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
68
71
  * timeout of 1,800s (30 minutes)
69
72
  */
70
- timeoutSeconds?: number | Expression<number> | null;
73
+ timeoutSeconds?: number | Expression<number> | ResetValue;
71
74
  /**
72
75
  * Min number of actual instances to be running at a given time.
76
+ *
77
+ * @remarks
73
78
  * Instances will be billed for memory allocation and 10% of CPU allocation
74
79
  * while idle.
75
- * A value of null restores the default min instances.
76
80
  */
77
- minInstances?: number | Expression<number> | null;
81
+ minInstances?: number | Expression<number> | ResetValue;
78
82
  /**
79
83
  * Max number of instances to be running in parallel.
80
- * A value of null restores the default max instances.
81
84
  */
82
- maxInstances?: number | Expression<number> | null;
85
+ maxInstances?: number | Expression<number> | ResetValue;
83
86
  /**
84
87
  * Number of requests a function can serve at once.
88
+ *
89
+ * @remarks
85
90
  * Can only be applied to functions running on Cloud Functions v2.
86
91
  * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
87
92
  * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
88
93
  * The maximum value for concurrency is 1,000.
89
94
  */
90
- concurrency?: number | Expression<number> | null;
95
+ concurrency?: number | Expression<number> | ResetValue;
91
96
  /**
92
97
  * Fractional number of CPUs to allocate to a function.
98
+ *
99
+ * @remarks
93
100
  * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
94
101
  * This is different from the defaults when using the gcloud utility and is different from
95
102
  * the fixed amount assigned in Google Cloud Functions generation 1.
96
103
  * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
97
104
  * to the value "gcf_gen1"
98
105
  */
99
- cpu?: number | 'gcf_gen1';
106
+ cpu?: number | "gcf_gen1";
100
107
  /**
101
108
  * Connect cloud function to specified VPC connector.
102
- * A value of null removes the VPC connector
103
109
  */
104
- vpcConnector?: string | null;
110
+ vpcConnector?: string | ResetValue;
105
111
  /**
106
112
  * Egress settings for VPC connector.
107
- * A value of null turns off VPC connector egress settings
108
113
  */
109
- vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
114
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
110
115
  /**
111
116
  * Specific service account for the function to run as.
112
- * A value of null restores the default service account.
113
117
  */
114
- serviceAccount?: string | null;
118
+ serviceAccount?: string | ResetValue;
115
119
  /**
116
120
  * Ingress settings which control where this function can be called from.
117
- * A value of null turns off ingress settings.
118
121
  */
119
- ingressSettings?: options.IngressSetting | null;
122
+ ingressSettings?: options.IngressSetting | ResetValue;
120
123
  /**
121
124
  * User labels to set on the function.
122
125
  */
123
126
  labels?: Record<string, string>;
124
- secrets?: string[];
127
+ secrets?: (string | SecretParam)[];
125
128
  /** Whether failed executions should be delivered again. */
126
- retry?: boolean | Expression<boolean> | null;
129
+ retry?: boolean | Expression<boolean> | ResetValue;
127
130
  }
128
131
  /**
129
132
  * Event handler which triggers when data is created, updated, or deleted in Realtime Database.
@@ -131,53 +134,53 @@ export interface ReferenceOptions extends options.EventHandlerOptions {
131
134
  * @param reference - The database reference path to trigger on.
132
135
  * @param handler - Event handler which is run every time a Realtime Database create, update, or delete occurs.
133
136
  */
134
- export declare function onValueWritten(reference: string, handler: (event: DatabaseEvent<Change<DataSnapshot>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>>>;
137
+ export declare function onValueWritten<Ref extends string>(ref: Ref, handler: (event: DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>>;
135
138
  /**
136
139
  * Event handler which triggers when data is created, updated, or deleted in Realtime Database.
137
140
  *
138
141
  * @param opts - Options that can be set on an individual event-handling function.
139
142
  * @param handler - Event handler which is run every time a Realtime Database create, update, or delete occurs.
140
143
  */
141
- export declare function onValueWritten(opts: ReferenceOptions, handler: (event: DatabaseEvent<Change<DataSnapshot>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>>>;
144
+ export declare function onValueWritten<Ref extends string>(opts: ReferenceOptions<Ref>, handler: (event: DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>>;
142
145
  /**
143
146
  * Event handler which triggers when data is created in Realtime Database.
144
147
  *
145
148
  * @param reference - The database reference path to trigger on.
146
149
  * @param handler - Event handler which is run every time a Realtime Database create occurs.
147
150
  */
148
- export declare function onValueCreated(reference: string, handler: (event: DatabaseEvent<DataSnapshot>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot>>;
151
+ export declare function onValueCreated<Ref extends string>(ref: Ref, handler: (event: DatabaseEvent<DataSnapshot, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot, ParamsOf<Ref>>>;
149
152
  /**
150
153
  * Event handler which triggers when data is created in Realtime Database.
151
154
  *
152
155
  * @param opts - Options that can be set on an individual event-handling function.
153
156
  * @param handler - Event handler which is run every time a Realtime Database create occurs.
154
157
  */
155
- export declare function onValueCreated(opts: ReferenceOptions, handler: (event: DatabaseEvent<DataSnapshot>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot>>;
158
+ export declare function onValueCreated<Ref extends string>(opts: ReferenceOptions<Ref>, handler: (event: DatabaseEvent<DataSnapshot, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot, ParamsOf<Ref>>>;
156
159
  /**
157
160
  * Event handler which triggers when data is updated in Realtime Database.
158
161
  *
159
162
  * @param reference - The database reference path to trigger on.
160
163
  * @param handler - Event handler which is run every time a Realtime Database update occurs.
161
164
  */
162
- export declare function onValueUpdated(reference: string, handler: (event: DatabaseEvent<Change<DataSnapshot>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>>>;
165
+ export declare function onValueUpdated<Ref extends string>(ref: Ref, handler: (event: DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>>;
163
166
  /**
164
167
  * Event handler which triggers when data is updated in Realtime Database.
165
168
  *
166
169
  * @param opts - Options that can be set on an individual event-handling function.
167
170
  * @param handler - Event handler which is run every time a Realtime Database update occurs.
168
171
  */
169
- export declare function onValueUpdated(opts: ReferenceOptions, handler: (event: DatabaseEvent<Change<DataSnapshot>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>>>;
172
+ export declare function onValueUpdated<Ref extends string>(opts: ReferenceOptions<Ref>, handler: (event: DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<Change<DataSnapshot>, ParamsOf<Ref>>>;
170
173
  /**
171
174
  * Event handler which triggers when data is deleted in Realtime Database.
172
175
  *
173
176
  * @param reference - The database reference path to trigger on.
174
177
  * @param handler - Event handler which is run every time a Realtime Database deletion occurs.
175
178
  */
176
- export declare function onValueDeleted(reference: string, handler: (event: DatabaseEvent<DataSnapshot>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot>>;
179
+ export declare function onValueDeleted<Ref extends string>(ref: Ref, handler: (event: DatabaseEvent<DataSnapshot, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot, ParamsOf<Ref>>>;
177
180
  /**
178
181
  * Event handler which triggers when data is deleted in Realtime Database.
179
182
  *
180
183
  * @param opts - Options that can be set on an individual event-handling function.
181
184
  * @param handler - Event handler which is run every time a Realtime Database deletion occurs.
182
185
  */
183
- export declare function onValueDeleted(opts: ReferenceOptions, handler: (event: DatabaseEvent<DataSnapshot>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot>>;
186
+ export declare function onValueDeleted<Ref extends string>(opts: ReferenceOptions<Ref>, handler: (event: DatabaseEvent<DataSnapshot, ParamsOf<Ref>>) => any | Promise<any>): CloudFunction<DatabaseEvent<DataSnapshot, ParamsOf<Ref>>>;
@@ -22,21 +22,23 @@
22
22
  // SOFTWARE.
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
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 apps_1 = require("../../apps");
25
+ const app_1 = require("../../common/app");
26
26
  const database_1 = require("../../common/providers/database");
27
27
  Object.defineProperty(exports, "DataSnapshot", { enumerable: true, get: function () { return database_1.DataSnapshot; } });
28
- const path_1 = require("../../utilities/path");
29
- const path_pattern_1 = require("../../utilities/path-pattern");
30
- const utils_1 = require("../../utils");
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");
31
33
  const options = require("../options");
32
34
  /** @internal */
33
- exports.writtenEventType = 'google.firebase.database.ref.v1.written';
35
+ exports.writtenEventType = "google.firebase.database.ref.v1.written";
34
36
  /** @internal */
35
- exports.createdEventType = 'google.firebase.database.ref.v1.created';
37
+ exports.createdEventType = "google.firebase.database.ref.v1.created";
36
38
  /** @internal */
37
- exports.updatedEventType = 'google.firebase.database.ref.v1.updated';
39
+ exports.updatedEventType = "google.firebase.database.ref.v1.updated";
38
40
  /** @internal */
39
- exports.deletedEventType = 'google.firebase.database.ref.v1.deleted';
41
+ exports.deletedEventType = "google.firebase.database.ref.v1.deleted";
40
42
  /**
41
43
  * Event handler which triggers when data is created, updated, or deleted in Realtime Database.
42
44
  *
@@ -80,15 +82,17 @@ function onValueDeleted(referenceOrOpts, handler) {
80
82
  exports.onValueDeleted = onValueDeleted;
81
83
  /** @internal */
82
84
  function getOpts(referenceOrOpts) {
83
- let path, instance, opts;
84
- if (typeof referenceOrOpts === 'string') {
85
+ let path;
86
+ let instance;
87
+ let opts;
88
+ if (typeof referenceOrOpts === "string") {
85
89
  path = (0, path_1.normalizePath)(referenceOrOpts);
86
- instance = '*';
90
+ instance = "*";
87
91
  opts = {};
88
92
  }
89
93
  else {
90
94
  path = (0, path_1.normalizePath)(referenceOrOpts.ref);
91
- instance = referenceOrOpts.instance || '*';
95
+ instance = referenceOrOpts.instance || "*";
92
96
  opts = { ...referenceOrOpts };
93
97
  delete opts.ref;
94
98
  delete opts.instance;
@@ -110,7 +114,7 @@ function makeParams(event, path, instance) {
110
114
  exports.makeParams = makeParams;
111
115
  /** @hidden */
112
116
  function makeDatabaseEvent(event, data, instance, params) {
113
- const snapshot = new database_1.DataSnapshot(data, event.ref, (0, apps_1.apps)().admin, instance);
117
+ const snapshot = new database_1.DataSnapshot(data, event.ref, (0, app_1.getApp)(), instance);
114
118
  const databaseEvent = {
115
119
  ...event,
116
120
  firebaseDatabaseHost: event.firebasedatabasehost,
@@ -122,8 +126,8 @@ function makeDatabaseEvent(event, data, instance, params) {
122
126
  }
123
127
  /** @hidden */
124
128
  function makeChangedDatabaseEvent(event, instance, params) {
125
- const before = new database_1.DataSnapshot(event.data.data, event.ref, (0, apps_1.apps)().admin, instance);
126
- const after = new database_1.DataSnapshot((0, utils_1.applyChange)(event.data.data, event.data.delta), event.ref, (0, apps_1.apps)().admin, instance);
129
+ const before = new database_1.DataSnapshot(event.data.data, event.ref, (0, app_1.getApp)(), instance);
130
+ const after = new database_1.DataSnapshot((0, utils_1.applyChange)(event.data.data, event.data.delta), event.ref, (0, app_1.getApp)(), instance);
127
131
  const databaseEvent = {
128
132
  ...event,
129
133
  firebaseDatabaseHost: event.firebasedatabasehost,
@@ -149,7 +153,8 @@ function makeEndpoint(eventType, opts, path, instance) {
149
153
  ? (eventFilterPathPatterns.instance = instance.getValue())
150
154
  : (eventFilters.instance = instance.getValue());
151
155
  return {
152
- platform: 'gcfv2',
156
+ ...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
157
+ platform: "gcfv2",
153
158
  ...baseOpts,
154
159
  ...specificOpts,
155
160
  labels: {
@@ -176,7 +181,7 @@ function onChangedOperation(eventType, referenceOrOpts, handler) {
176
181
  const instanceUrl = `https://${event.instance}.${event.firebasedatabasehost}`;
177
182
  const params = makeParams(event, pathPattern, instancePattern);
178
183
  const databaseEvent = makeChangedDatabaseEvent(event, instanceUrl, params);
179
- return handler(databaseEvent);
184
+ return (0, trace_1.wrapTraceContext)(handler)(databaseEvent);
180
185
  };
181
186
  func.run = handler;
182
187
  func.__endpoint = makeEndpoint(eventType, opts, pathPattern, instancePattern);
@@ -1,6 +1,8 @@
1
- import { CloudEvent, CloudFunction } from '../core';
2
- import * as options from '../options';
3
- import { Expression } from '../params';
1
+ import { ResetValue } from "../../common/options";
2
+ import { CloudEvent, CloudFunction } from "../core";
3
+ import { Expression } from "../../params";
4
+ import * as options from "../options";
5
+ import { SecretParam } from "../../params/types";
4
6
  /** Options that can be set on an Eventarc trigger. */
5
7
  export interface EventarcTriggerOptions extends options.EventHandlerOptions {
6
8
  /**
@@ -32,76 +34,76 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions {
32
34
  region?: options.SupportedRegion | string;
33
35
  /**
34
36
  * Amount of memory to allocate to a function.
35
- * A value of null restores the defaults of 256MB.
36
37
  */
37
- memory?: options.MemoryOption | Expression<number> | null;
38
+ memory?: options.MemoryOption | Expression<number> | ResetValue;
38
39
  /**
39
40
  * Timeout for the function in sections, possible values are 0 to 540.
40
41
  * HTTPS functions can specify a higher timeout.
41
- * A value of null restores the default of 60s
42
+ *
43
+ * @remarks
42
44
  * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
43
45
  * function depends on the type of function: Event handling functions have a
44
46
  * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
45
47
  * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
46
48
  * timeout of 1,800s (30 minutes)
47
49
  */
48
- timeoutSeconds?: number | Expression<number> | null;
50
+ timeoutSeconds?: number | Expression<number> | ResetValue;
49
51
  /**
50
52
  * Min number of actual instances to be running at a given time.
53
+ *
54
+ * @remarks
51
55
  * Instances will be billed for memory allocation and 10% of CPU allocation
52
56
  * while idle.
53
- * A value of null restores the default min instances.
54
57
  */
55
- minInstances?: number | Expression<number> | null;
58
+ minInstances?: number | Expression<number> | ResetValue;
56
59
  /**
57
60
  * Max number of instances to be running in parallel.
58
- * A value of null restores the default max instances.
59
61
  */
60
- maxInstances?: number | Expression<number> | null;
62
+ maxInstances?: number | Expression<number> | ResetValue;
61
63
  /**
62
64
  * Number of requests a function can serve at once.
65
+ *
66
+ * @remarks
63
67
  * Can only be applied to functions running on Cloud Functions v2.
64
68
  * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
65
69
  * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
66
70
  * The maximum value for concurrency is 1,000.
67
71
  */
68
- concurrency?: number | Expression<number> | null;
72
+ concurrency?: number | Expression<number> | ResetValue;
69
73
  /**
70
74
  * Fractional number of CPUs to allocate to a function.
75
+ *
76
+ * @remarks
71
77
  * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
72
78
  * This is different from the defaults when using the gcloud utility and is different from
73
79
  * the fixed amount assigned in Google Cloud Functions generation 1.
74
80
  * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
75
81
  * to the value "gcf_gen1"
76
82
  */
77
- cpu?: number | 'gcf_gen1';
83
+ cpu?: number | "gcf_gen1";
78
84
  /**
79
85
  * Connect cloud function to specified VPC connector.
80
- * A value of null removes the VPC connector
81
86
  */
82
- vpcConnector?: string | null;
87
+ vpcConnector?: string | ResetValue;
83
88
  /**
84
89
  * Egress settings for VPC connector.
85
- * A value of null turns off VPC connector egress settings
86
90
  */
87
- vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
91
+ vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
88
92
  /**
89
93
  * Specific service account for the function to run as.
90
- * A value of null restores the default service account.
91
94
  */
92
- serviceAccount?: string | null;
95
+ serviceAccount?: string | ResetValue;
93
96
  /**
94
97
  * Ingress settings which control where this function can be called from.
95
- * A value of null turns off ingress settings.
96
98
  */
97
- ingressSettings?: options.IngressSetting | null;
99
+ ingressSettings?: options.IngressSetting | ResetValue;
98
100
  /**
99
101
  * User labels to set on the function.
100
102
  */
101
103
  labels?: Record<string, string>;
102
- secrets?: string[];
104
+ secrets?: (string | SecretParam)[];
103
105
  /** Whether failed executions should be delivered again. */
104
- retry?: boolean;
106
+ retry?: boolean | Expression<boolean> | ResetValue;
105
107
  }
106
108
  /** Handles an Eventarc event published on the default channel.
107
109
  * @param eventType - Type of the event to trigger on.
@@ -27,27 +27,30 @@ exports.onCustomEventPublished = void 0;
27
27
  * @packageDocumentation
28
28
  */
29
29
  const encoding_1 = require("../../common/encoding");
30
+ const manifest_1 = require("../../runtime/manifest");
31
+ const trace_1 = require("../trace");
30
32
  const options = require("../options");
31
33
  function onCustomEventPublished(eventTypeOrOpts, handler) {
32
34
  var _a;
33
35
  let opts;
34
- if (typeof eventTypeOrOpts === 'string') {
36
+ if (typeof eventTypeOrOpts === "string") {
35
37
  opts = {
36
38
  eventType: eventTypeOrOpts,
37
39
  };
38
40
  }
39
- else if (typeof eventTypeOrOpts === 'object') {
41
+ else if (typeof eventTypeOrOpts === "object") {
40
42
  opts = eventTypeOrOpts;
41
43
  }
42
44
  const func = (raw) => {
43
- return handler(raw);
45
+ return (0, trace_1.wrapTraceContext)(handler)(raw);
44
46
  };
45
47
  func.run = handler;
46
- const channel = (_a = opts.channel) !== null && _a !== void 0 ? _a : 'locations/us-central1/channels/firebase';
48
+ const channel = (_a = opts.channel) !== null && _a !== void 0 ? _a : "locations/us-central1/channels/firebase";
47
49
  const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
48
50
  const specificOpts = options.optionsToEndpoint(opts);
49
51
  const endpoint = {
50
- platform: 'gcfv2',
52
+ ...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
53
+ platform: "gcfv2",
51
54
  ...baseOpts,
52
55
  ...specificOpts,
53
56
  labels: {
@@ -61,8 +64,8 @@ function onCustomEventPublished(eventTypeOrOpts, handler) {
61
64
  channel,
62
65
  },
63
66
  };
64
- (0, encoding_1.convertIfPresent)(endpoint.eventTrigger, opts, 'eventFilters', 'filters');
65
- (0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, 'retry');
67
+ (0, encoding_1.convertIfPresent)(endpoint.eventTrigger, opts, "eventFilters", "filters");
68
+ (0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, "retry");
66
69
  func.__endpoint = endpoint;
67
70
  return func;
68
71
  }