firebase-functions 7.1.1 → 7.2.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.
- package/lib/esm/params/index.mjs +24 -10
- package/lib/esm/params/types.mjs +57 -7
- package/lib/esm/v1/cloud-functions.mjs +9 -4
- package/lib/esm/v1/providers/analytics.mjs +3 -2
- package/lib/esm/v1/providers/database.mjs +6 -4
- package/lib/esm/v1/providers/firestore.mjs +17 -5
- package/lib/esm/v1/providers/pubsub.mjs +8 -5
- package/lib/esm/v1/providers/storage.mjs +6 -5
- package/lib/esm/v2/options.mjs +34 -5
- package/lib/esm/v2/providers/database.mjs +10 -2
- package/lib/params/index.d.ts +15 -4
- package/lib/params/index.js +23 -8
- package/lib/params/types.d.ts +29 -4
- package/lib/params/types.js +62 -7
- package/lib/runtime/manifest.d.ts +6 -1
- package/lib/v1/cloud-functions.js +9 -4
- package/lib/v1/function-configuration.d.ts +2 -2
- package/lib/v1/providers/analytics.d.ts +2 -4
- package/lib/v1/providers/analytics.js +3 -2
- package/lib/v1/providers/database.d.ts +6 -5
- package/lib/v1/providers/database.js +6 -4
- package/lib/v1/providers/firestore.d.ts +9 -9
- package/lib/v1/providers/firestore.js +24 -13
- package/lib/v1/providers/pubsub.d.ts +5 -4
- package/lib/v1/providers/pubsub.js +8 -5
- package/lib/v1/providers/storage.d.ts +2 -1
- package/lib/v1/providers/storage.js +6 -5
- package/lib/v2/options.d.ts +35 -0
- package/lib/v2/options.js +34 -5
- package/lib/v2/providers/database.d.ts +18 -0
- package/lib/v2/providers/database.js +10 -2
- package/package.json +1 -1
package/lib/params/types.d.ts
CHANGED
|
@@ -15,6 +15,22 @@ export declare abstract class Expression<T extends string | number | boolean | s
|
|
|
15
15
|
/** Returns the expression's representation as JSON. */
|
|
16
16
|
toJSON(): string;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* An InterpolationExpression allows string fragments and Expressions to be
|
|
20
|
+
* joined natively into a new Expression block evaluating to a string string.
|
|
21
|
+
*/
|
|
22
|
+
export declare class InterpolationExpression extends Expression<string> {
|
|
23
|
+
private strings;
|
|
24
|
+
private values;
|
|
25
|
+
constructor(strings: TemplateStringsArray, values: (string | Expression<any>)[]);
|
|
26
|
+
toCEL(): string;
|
|
27
|
+
}
|
|
28
|
+
export declare function valueOf<T extends string | number | boolean | string[]>(arg: T | Expression<T>): T;
|
|
29
|
+
export declare function celOf<T extends string | number | boolean | string[]>(arg: T | Expression<T>): T | string;
|
|
30
|
+
/**
|
|
31
|
+
* Transforms a string or a string expression using a function.
|
|
32
|
+
*/
|
|
33
|
+
export declare function transform(source: string | Expression<string>, transformer: (val: string) => string): Expression<string>;
|
|
18
34
|
/**
|
|
19
35
|
* A CEL expression corresponding to a ternary operator, e.g {{ cond ? ifTrue : ifFalse }}
|
|
20
36
|
*/
|
|
@@ -31,9 +47,9 @@ export declare class TernaryExpression<T extends string | number | boolean | str
|
|
|
31
47
|
*/
|
|
32
48
|
export declare class CompareExpression<T extends string | number | boolean | string[]> extends Expression<boolean> {
|
|
33
49
|
cmp: "==" | "!=" | ">" | ">=" | "<" | "<=";
|
|
34
|
-
lhs: Expression<T>;
|
|
50
|
+
lhs: T | Expression<T>;
|
|
35
51
|
rhs: T | Expression<T>;
|
|
36
|
-
constructor(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", lhs: Expression<T>, rhs: T | Expression<T>);
|
|
52
|
+
constructor(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", lhs: T | Expression<T>, rhs: T | Expression<T>);
|
|
37
53
|
toString(): string;
|
|
38
54
|
/** Returns a `TernaryExpression` which can resolve to one of two values, based on the resolution of this comparison. */
|
|
39
55
|
thenElse<retT extends string | number | boolean | string[]>(ifTrue: retT | Expression<retT>, ifFalse: retT | Expression<retT>): TernaryExpression<retT>;
|
|
@@ -145,6 +161,13 @@ export type WireParamSpec<T extends string | number | boolean | string[]> = {
|
|
|
145
161
|
};
|
|
146
162
|
/** Configuration options which can be used to customize the prompting behavior of a parameter. */
|
|
147
163
|
export type ParamOptions<T extends string | number | boolean | string[]> = Omit<ParamSpec<T>, "name" | "type">;
|
|
164
|
+
/** Configuration options which can be used to customize the behavior of a secret parameter. */
|
|
165
|
+
export interface SecretParamOptions {
|
|
166
|
+
/** An optional human-readable string to be used as a replacement for the parameter's name when prompting. */
|
|
167
|
+
label?: string;
|
|
168
|
+
/** An optional long-form description of the parameter to be displayed while prompting. */
|
|
169
|
+
description?: string;
|
|
170
|
+
}
|
|
148
171
|
/**
|
|
149
172
|
* Represents a parametrized value that will be read from .env files if present,
|
|
150
173
|
* or prompted for by the CLI if missing. Instantiate these with the defineX
|
|
@@ -183,9 +206,10 @@ export declare abstract class Param<T extends string | number | boolean | string
|
|
|
183
206
|
* during execution of that Function.
|
|
184
207
|
*/
|
|
185
208
|
export declare class SecretParam {
|
|
209
|
+
readonly options: SecretParamOptions;
|
|
186
210
|
static type: ParamValueType;
|
|
187
211
|
name: string;
|
|
188
|
-
constructor(name: string);
|
|
212
|
+
constructor(name: string, options?: SecretParamOptions);
|
|
189
213
|
/** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
|
|
190
214
|
value(): string;
|
|
191
215
|
}
|
|
@@ -197,9 +221,10 @@ export declare class SecretParam {
|
|
|
197
221
|
* of that Function.
|
|
198
222
|
*/
|
|
199
223
|
export declare class JsonSecretParam<T = any> {
|
|
224
|
+
readonly options: SecretParamOptions;
|
|
200
225
|
static type: ParamValueType;
|
|
201
226
|
name: string;
|
|
202
|
-
constructor(name: string);
|
|
227
|
+
constructor(name: string, options?: SecretParamOptions);
|
|
203
228
|
/** 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. */
|
|
204
229
|
value(): T;
|
|
205
230
|
}
|
package/lib/params/types.js
CHANGED
|
@@ -37,9 +37,56 @@ var Expression = class {
|
|
|
37
37
|
return this.toString();
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* An InterpolationExpression allows string fragments and Expressions to be
|
|
42
|
+
* joined natively into a new Expression block evaluating to a string string.
|
|
43
|
+
*/
|
|
44
|
+
var InterpolationExpression = class extends Expression {
|
|
45
|
+
constructor(strings, values) {
|
|
46
|
+
super();
|
|
47
|
+
this.strings = strings;
|
|
48
|
+
this.values = values;
|
|
49
|
+
}
|
|
50
|
+
/** @internal */
|
|
51
|
+
runtimeValue() {
|
|
52
|
+
return this.strings.reduce((result, str, i) => {
|
|
53
|
+
const val = i < this.values.length ? String(valueOf(this.values[i])) : "";
|
|
54
|
+
return result + str + val;
|
|
55
|
+
}, "");
|
|
56
|
+
}
|
|
57
|
+
toCEL() {
|
|
58
|
+
return this.strings.reduce((result, str, i) => {
|
|
59
|
+
const val = i < this.values.length ? celOf(this.values[i]) : "";
|
|
60
|
+
return result + str + val;
|
|
61
|
+
}, "");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/** @internal */
|
|
65
|
+
var TransformedStringExpression = class extends Expression {
|
|
66
|
+
constructor(source, transformer) {
|
|
67
|
+
super();
|
|
68
|
+
this.source = source;
|
|
69
|
+
this.transformer = transformer;
|
|
70
|
+
}
|
|
71
|
+
runtimeValue() {
|
|
72
|
+
return this.transformer(valueOf(this.source));
|
|
73
|
+
}
|
|
74
|
+
toCEL() {
|
|
75
|
+
return this.source instanceof Expression ? this.source.toCEL() : this.transformer(this.source);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
40
78
|
function valueOf(arg) {
|
|
41
79
|
return arg instanceof Expression ? arg.runtimeValue() : arg;
|
|
42
80
|
}
|
|
81
|
+
function celOf(arg) {
|
|
82
|
+
return arg instanceof Expression ? arg.toCEL() : arg;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Transforms a string or a string expression using a function.
|
|
86
|
+
*/
|
|
87
|
+
function transform(source, transformer) {
|
|
88
|
+
return new TransformedStringExpression(source, transformer);
|
|
89
|
+
}
|
|
43
90
|
/**
|
|
44
91
|
* Returns how an entity (either an `Expression` or a literal value) should be represented in CEL.
|
|
45
92
|
* - Expressions delegate to the `.toString()` method, which is used by the WireManifest
|
|
@@ -91,7 +138,7 @@ var CompareExpression = class extends Expression {
|
|
|
91
138
|
}
|
|
92
139
|
/** @internal */
|
|
93
140
|
runtimeValue() {
|
|
94
|
-
const left = this.lhs
|
|
141
|
+
const left = valueOf(this.lhs);
|
|
95
142
|
const right = valueOf(this.rhs);
|
|
96
143
|
switch (this.cmp) {
|
|
97
144
|
case "==": return Array.isArray(left) ? this.arrayEquals(left, right) : left === right;
|
|
@@ -108,8 +155,7 @@ var CompareExpression = class extends Expression {
|
|
|
108
155
|
return a.every((item) => b.includes(item)) && b.every((item) => a.includes(item));
|
|
109
156
|
}
|
|
110
157
|
toString() {
|
|
111
|
-
|
|
112
|
-
return `${this.lhs} ${this.cmp} ${rhsStr}`;
|
|
158
|
+
return `${refOf(this.lhs)} ${this.cmp} ${refOf(this.rhs)}`;
|
|
113
159
|
}
|
|
114
160
|
/** Returns a `TernaryExpression` which can resolve to one of two values, based on the resolution of this comparison. */
|
|
115
161
|
thenElse(ifTrue, ifFalse) {
|
|
@@ -231,7 +277,8 @@ var SecretParam = class {
|
|
|
231
277
|
static {
|
|
232
278
|
this.type = "secret";
|
|
233
279
|
}
|
|
234
|
-
constructor(name) {
|
|
280
|
+
constructor(name, options = {}) {
|
|
281
|
+
this.options = options;
|
|
235
282
|
this.name = name;
|
|
236
283
|
}
|
|
237
284
|
/** @internal */
|
|
@@ -246,7 +293,8 @@ var SecretParam = class {
|
|
|
246
293
|
toSpec() {
|
|
247
294
|
return {
|
|
248
295
|
type: "secret",
|
|
249
|
-
name: this.name
|
|
296
|
+
name: this.name,
|
|
297
|
+
...this.options
|
|
250
298
|
};
|
|
251
299
|
}
|
|
252
300
|
/** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
|
|
@@ -268,7 +316,8 @@ var JsonSecretParam = class {
|
|
|
268
316
|
static {
|
|
269
317
|
this.type = "secret";
|
|
270
318
|
}
|
|
271
|
-
constructor(name) {
|
|
319
|
+
constructor(name, options = {}) {
|
|
320
|
+
this.options = options;
|
|
272
321
|
this.name = name;
|
|
273
322
|
}
|
|
274
323
|
/** @internal */
|
|
@@ -288,6 +337,7 @@ var JsonSecretParam = class {
|
|
|
288
337
|
return {
|
|
289
338
|
type: "secret",
|
|
290
339
|
name: this.name,
|
|
340
|
+
...this.options,
|
|
291
341
|
format: "json"
|
|
292
342
|
};
|
|
293
343
|
}
|
|
@@ -417,11 +467,16 @@ exports.Expression = Expression;
|
|
|
417
467
|
exports.FloatParam = FloatParam;
|
|
418
468
|
exports.IntParam = IntParam;
|
|
419
469
|
exports.InternalExpression = InternalExpression;
|
|
470
|
+
exports.InterpolationExpression = InterpolationExpression;
|
|
420
471
|
exports.JsonSecretParam = JsonSecretParam;
|
|
421
472
|
exports.ListParam = ListParam;
|
|
422
473
|
exports.Param = Param;
|
|
423
474
|
exports.SecretParam = SecretParam;
|
|
424
475
|
exports.StringParam = StringParam;
|
|
425
476
|
exports.TernaryExpression = TernaryExpression;
|
|
477
|
+
exports.TransformedStringExpression = TransformedStringExpression;
|
|
478
|
+
exports.celOf = celOf;
|
|
426
479
|
exports.multiSelect = multiSelect;
|
|
427
|
-
exports.select = select;
|
|
480
|
+
exports.select = select;
|
|
481
|
+
exports.transform = transform;
|
|
482
|
+
exports.valueOf = valueOf;
|
|
@@ -27,8 +27,13 @@ export interface ManifestEndpoint {
|
|
|
27
27
|
concurrency?: number | Expression<number> | ResetValue;
|
|
28
28
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
29
29
|
vpc?: {
|
|
30
|
-
connector
|
|
30
|
+
connector?: string | Expression<string>;
|
|
31
31
|
egressSettings?: string | Expression<string> | ResetValue;
|
|
32
|
+
networkInterfaces?: Array<{
|
|
33
|
+
network?: string | Expression<string> | ResetValue;
|
|
34
|
+
subnetwork?: string | Expression<string> | ResetValue;
|
|
35
|
+
tags?: string | string[] | Expression<string> | Expression<string[]> | ResetValue;
|
|
36
|
+
}> | ResetValue;
|
|
32
37
|
} | ResetValue;
|
|
33
38
|
serviceAccountEmail?: string | Expression<string> | ResetValue;
|
|
34
39
|
cpu?: number | "gcf_gen1";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_logger_index = require('../logger/index.js');
|
|
2
|
+
const require_params_types = require('../params/types.js');
|
|
2
3
|
const require_common_options = require('../common/options.js');
|
|
3
4
|
const require_runtime_manifest = require('../runtime/manifest.js');
|
|
4
5
|
const require_common_change = require('../common/change.js');
|
|
@@ -55,10 +56,11 @@ function makeCloudFunction({ contextOnlyHandler, dataConstructor = (raw) => raw.
|
|
|
55
56
|
if (triggerResource() == null) {
|
|
56
57
|
return {};
|
|
57
58
|
}
|
|
59
|
+
const tr = triggerResource();
|
|
58
60
|
const trigger = {
|
|
59
61
|
...optionsToTrigger(options),
|
|
60
62
|
eventTrigger: {
|
|
61
|
-
resource:
|
|
63
|
+
resource: require_params_types.celOf(tr),
|
|
62
64
|
eventType: legacyEventType || provider + "." + eventType,
|
|
63
65
|
service
|
|
64
66
|
}
|
|
@@ -81,13 +83,16 @@ function makeCloudFunction({ contextOnlyHandler, dataConstructor = (raw) => raw.
|
|
|
81
83
|
...optionsToEndpoint(options)
|
|
82
84
|
};
|
|
83
85
|
if (options.schedule) {
|
|
84
|
-
endpoint.scheduleTrigger = require_runtime_manifest.initV1ScheduleTrigger(options.schedule.schedule, options);
|
|
86
|
+
endpoint.scheduleTrigger = require_runtime_manifest.initV1ScheduleTrigger(require_params_types.celOf(options.schedule.schedule), options);
|
|
85
87
|
require_common_encoding.copyIfPresent(endpoint.scheduleTrigger, options.schedule, "timeZone");
|
|
88
|
+
if (endpoint.scheduleTrigger.timeZone instanceof require_params_types.Expression) {
|
|
89
|
+
endpoint.scheduleTrigger.timeZone = endpoint.scheduleTrigger.timeZone.toCEL();
|
|
90
|
+
}
|
|
86
91
|
require_common_encoding.copyIfPresent(endpoint.scheduleTrigger.retryConfig, options.schedule.retryConfig, "retryCount", "maxDoublings", "maxBackoffDuration", "maxRetryDuration", "minBackoffDuration");
|
|
87
92
|
} else {
|
|
88
93
|
endpoint.eventTrigger = {
|
|
89
94
|
eventType: legacyEventType || provider + "." + eventType,
|
|
90
|
-
eventFilters: { resource: triggerResource() },
|
|
95
|
+
eventFilters: { resource: require_params_types.celOf(triggerResource()) },
|
|
91
96
|
retry: !!options.failurePolicy
|
|
92
97
|
};
|
|
93
98
|
}
|
|
@@ -110,7 +115,7 @@ function _makeParams(context, triggerResourceGetter) {
|
|
|
110
115
|
if (!context.resource) {
|
|
111
116
|
return {};
|
|
112
117
|
}
|
|
113
|
-
const triggerResource = triggerResourceGetter();
|
|
118
|
+
const triggerResource = require_params_types.valueOf(triggerResourceGetter());
|
|
114
119
|
const wildcards = triggerResource.match(WILDCARD_REGEX);
|
|
115
120
|
const params = {};
|
|
116
121
|
const eventResourceParts = context?.resource?.name?.split?.("/");
|
|
@@ -85,13 +85,13 @@ export interface Schedule {
|
|
|
85
85
|
* schedule: "every 5 minutes"
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
|
-
schedule: string
|
|
88
|
+
schedule: string | Expression<string>;
|
|
89
89
|
/**
|
|
90
90
|
* Specifies the time zone to be used in interpreting {@link Schedule.schedule}.
|
|
91
91
|
*
|
|
92
92
|
* The value of this field must be a time zone name from the tz database.
|
|
93
93
|
*/
|
|
94
|
-
timeZone?: string | ResetValue;
|
|
94
|
+
timeZone?: string | Expression<string> | ResetValue;
|
|
95
95
|
/**
|
|
96
96
|
* Settings that determine the retry behavior.
|
|
97
97
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CloudFunction, EventContext } from "../cloud-functions";
|
|
2
|
-
import {
|
|
2
|
+
import { Expression } from "../../params/types";
|
|
3
3
|
/**
|
|
4
4
|
* Registers a function to handle analytics events.
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@ import { DeploymentOptions } from "../function-configuration";
|
|
|
8
8
|
*
|
|
9
9
|
* @returns Analytics event builder interface.
|
|
10
10
|
*/
|
|
11
|
-
export declare function event(analyticsEventType: string): AnalyticsEventBuilder;
|
|
11
|
+
export declare function event(analyticsEventType: string | Expression<string>): AnalyticsEventBuilder;
|
|
12
12
|
/**
|
|
13
13
|
* The Firebase Analytics event builder interface.
|
|
14
14
|
*
|
|
@@ -17,8 +17,6 @@ export declare function event(analyticsEventType: string): AnalyticsEventBuilder
|
|
|
17
17
|
export declare class AnalyticsEventBuilder {
|
|
18
18
|
private triggerResource;
|
|
19
19
|
private options;
|
|
20
|
-
/** @hidden */
|
|
21
|
-
constructor(triggerResource: () => string, options: DeploymentOptions);
|
|
22
20
|
/**
|
|
23
21
|
* Event handler that fires every time a Firebase Analytics event occurs.
|
|
24
22
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_params_index = require('../../params/index.js');
|
|
2
3
|
const require_v1_cloud_functions = require('../cloud-functions.js');
|
|
3
4
|
|
|
4
5
|
//#region src/v1/providers/analytics.ts
|
|
@@ -34,7 +35,7 @@ function _eventWithOptions(analyticsEventType, options) {
|
|
|
34
35
|
if (!process.env.GCLOUD_PROJECT) {
|
|
35
36
|
throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
|
36
37
|
}
|
|
37
|
-
return
|
|
38
|
+
return require_params_index.expr`projects/${process.env.GCLOUD_PROJECT}/events/${analyticsEventType}`;
|
|
38
39
|
}, options);
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
@@ -43,7 +44,7 @@ function _eventWithOptions(analyticsEventType, options) {
|
|
|
43
44
|
* Access via `functions.analytics.event()`.
|
|
44
45
|
*/
|
|
45
46
|
var AnalyticsEventBuilder = class {
|
|
46
|
-
/** @
|
|
47
|
+
/** @internal */
|
|
47
48
|
constructor(triggerResource, options) {
|
|
48
49
|
this.triggerResource = triggerResource;
|
|
49
50
|
this.options = options;
|
|
@@ -3,6 +3,7 @@ import { ParamsOf } from "../../common/params";
|
|
|
3
3
|
import { DataSnapshot } from "../../common/providers/database";
|
|
4
4
|
import { CloudFunction, EventContext } from "../cloud-functions";
|
|
5
5
|
import { DeploymentOptions } from "../function-configuration";
|
|
6
|
+
import { Expression } from "../../params/types";
|
|
6
7
|
export { DataSnapshot };
|
|
7
8
|
/**
|
|
8
9
|
* Registers a function that triggers on events from a specific
|
|
@@ -19,7 +20,7 @@ export { DataSnapshot };
|
|
|
19
20
|
* to watch for write events.
|
|
20
21
|
* @returns Firebase Realtime Database instance builder interface.
|
|
21
22
|
*/
|
|
22
|
-
export declare function instance(instance: string): InstanceBuilder;
|
|
23
|
+
export declare function instance(instance: string | Expression<string>): InstanceBuilder;
|
|
23
24
|
/**
|
|
24
25
|
* Registers a function that triggers on Firebase Realtime Database write
|
|
25
26
|
* events.
|
|
@@ -52,7 +53,7 @@ export declare function instance(instance: string): InstanceBuilder;
|
|
|
52
53
|
* @param path The path within the Database to watch for write events.
|
|
53
54
|
* @returns Firebase Realtime Database builder interface.
|
|
54
55
|
*/
|
|
55
|
-
export declare function ref<Ref extends string>(path: Ref): RefBuilder<Ref>;
|
|
56
|
+
export declare function ref<Ref extends string>(path: Ref | Expression<string>): RefBuilder<Ref>;
|
|
56
57
|
/**
|
|
57
58
|
* The Firebase Realtime Database instance builder interface.
|
|
58
59
|
*
|
|
@@ -61,11 +62,11 @@ export declare function ref<Ref extends string>(path: Ref): RefBuilder<Ref>;
|
|
|
61
62
|
export declare class InstanceBuilder {
|
|
62
63
|
private instance;
|
|
63
64
|
private options;
|
|
64
|
-
constructor(instance: string
|
|
65
|
+
constructor(instance: string | Expression<string>, options: DeploymentOptions);
|
|
65
66
|
/**
|
|
66
67
|
* @returns Firebase Realtime Database reference builder interface.
|
|
67
68
|
*/
|
|
68
|
-
ref<Ref extends string>(path: Ref): RefBuilder<Ref>;
|
|
69
|
+
ref<Ref extends string>(path: Ref | Expression<string>): RefBuilder<Ref>;
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
72
|
* The Firebase Realtime Database reference builder interface.
|
|
@@ -75,7 +76,7 @@ export declare class InstanceBuilder {
|
|
|
75
76
|
export declare class RefBuilder<Ref extends string> {
|
|
76
77
|
private triggerResource;
|
|
77
78
|
private options;
|
|
78
|
-
constructor(triggerResource: () => string
|
|
79
|
+
constructor(triggerResource: () => string | Expression<string>, options: DeploymentOptions);
|
|
79
80
|
/**
|
|
80
81
|
* Event handler that fires every time a Firebase Realtime Database write
|
|
81
82
|
* of any kind (creation, update, or delete) occurs.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_params_types = require('../../params/types.js');
|
|
3
|
+
const require_params_index = require('../../params/index.js');
|
|
2
4
|
const require_common_config = require('../../common/config.js');
|
|
3
5
|
const require_common_app = require('../../common/app.js');
|
|
4
6
|
const require_v1_cloud_functions = require('../cloud-functions.js');
|
|
@@ -96,14 +98,14 @@ var InstanceBuilder = class {
|
|
|
96
98
|
* @returns Firebase Realtime Database reference builder interface.
|
|
97
99
|
*/
|
|
98
100
|
ref(path) {
|
|
99
|
-
const normalized = require_common_utilities_path.normalizePath
|
|
100
|
-
return new RefBuilder(() => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
|
|
101
|
+
const normalized = require_params_types.transform(path, require_common_utilities_path.normalizePath);
|
|
102
|
+
return new RefBuilder(() => require_params_index.expr`projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
|
|
101
103
|
}
|
|
102
104
|
};
|
|
103
105
|
/** @internal */
|
|
104
106
|
function _refWithOptions(path, options) {
|
|
105
107
|
const resourceGetter = () => {
|
|
106
|
-
const normalized = require_common_utilities_path.normalizePath
|
|
108
|
+
const normalized = require_params_types.transform(path, require_common_utilities_path.normalizePath);
|
|
107
109
|
const databaseURL = require_common_config.firebaseConfig().databaseURL;
|
|
108
110
|
if (!databaseURL) {
|
|
109
111
|
throw new Error("Missing expected firebase config value databaseURL, " + "config is actually" + JSON.stringify(require_common_config.firebaseConfig()) + "\n If you are unit testing, please set process.env.FIREBASE_CONFIG");
|
|
@@ -121,7 +123,7 @@ function _refWithOptions(path, options) {
|
|
|
121
123
|
if (!instance$1) {
|
|
122
124
|
throw new Error("Invalid value for config firebase.databaseURL: " + databaseURL);
|
|
123
125
|
}
|
|
124
|
-
return `projects/_/instances/${instance$1}/refs/${normalized}`;
|
|
126
|
+
return require_params_index.expr`projects/_/instances/${instance$1}/refs/${normalized}`;
|
|
125
127
|
};
|
|
126
128
|
return new RefBuilder(resourceGetter, options);
|
|
127
129
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as firestore from "firebase-admin/firestore";
|
|
2
|
+
import { Expression } from "../../params/types";
|
|
2
3
|
import { Change } from "../../common/change";
|
|
3
4
|
import { ParamsOf } from "../../common/params";
|
|
4
5
|
import { CloudFunction, LegacyEvent, EventContext } from "../cloud-functions";
|
|
@@ -12,29 +13,28 @@ export type QueryDocumentSnapshot = firestore.QueryDocumentSnapshot;
|
|
|
12
13
|
* collection is named "users" and the document is named "Ada", then the
|
|
13
14
|
* path is "/users/Ada".
|
|
14
15
|
*/
|
|
15
|
-
export declare function document<Path extends string>(path: Path): DocumentBuilder<Path>;
|
|
16
|
-
export declare function namespace(namespace: string): NamespaceBuilder;
|
|
17
|
-
export declare function database(database: string): DatabaseBuilder;
|
|
16
|
+
export declare function document<Path extends string>(path: Path | Expression<string>): DocumentBuilder<Path>;
|
|
17
|
+
export declare function namespace(namespace: string | Expression<string>): NamespaceBuilder;
|
|
18
|
+
export declare function database(database: string | Expression<string>): DatabaseBuilder;
|
|
18
19
|
export declare class DatabaseBuilder {
|
|
19
20
|
private database;
|
|
20
21
|
private options;
|
|
21
|
-
constructor(database: string
|
|
22
|
-
namespace(namespace: string): NamespaceBuilder;
|
|
23
|
-
document<Path extends string>(path: Path): DocumentBuilder<Path>;
|
|
22
|
+
constructor(database: string | Expression<string>, options: DeploymentOptions);
|
|
23
|
+
namespace(namespace: string | Expression<string>): NamespaceBuilder;
|
|
24
|
+
document<Path extends string>(path: Path | Expression<string>): DocumentBuilder<Path>;
|
|
24
25
|
}
|
|
25
26
|
export declare class NamespaceBuilder {
|
|
26
27
|
private database;
|
|
27
28
|
private options;
|
|
28
29
|
private namespace?;
|
|
29
|
-
constructor(database: string
|
|
30
|
-
document<Path extends string>(path: Path): DocumentBuilder<Path>;
|
|
30
|
+
constructor(database: string | Expression<string>, options: DeploymentOptions, namespace?: string | Expression<string>);
|
|
31
|
+
document<Path extends string>(path: Path | Expression<string>): DocumentBuilder<Path>;
|
|
31
32
|
}
|
|
32
33
|
export declare function snapshotConstructor(event: LegacyEvent): DocumentSnapshot;
|
|
33
34
|
export declare function beforeSnapshotConstructor(event: LegacyEvent): DocumentSnapshot;
|
|
34
35
|
export declare class DocumentBuilder<Path extends string> {
|
|
35
36
|
private triggerResource;
|
|
36
37
|
private options;
|
|
37
|
-
constructor(triggerResource: () => string, options: DeploymentOptions);
|
|
38
38
|
/** Respond to all document writes (creates, updates, or deletes). */
|
|
39
39
|
onWrite(handler: (change: Change<DocumentSnapshot>, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any): CloudFunction<Change<DocumentSnapshot>>;
|
|
40
40
|
/** Respond only to document updates. */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_params_types = require('../../params/types.js');
|
|
3
|
+
const require_params_index = require('../../params/index.js');
|
|
2
4
|
const require_common_change = require('../../common/change.js');
|
|
3
5
|
const require_v1_cloud_functions = require('../cloud-functions.js');
|
|
4
6
|
const require_common_providers_firestore = require('../../common/providers/firestore.js');
|
|
5
|
-
let path = require("path");
|
|
6
|
-
path = require_rolldown_runtime.__toESM(path);
|
|
7
7
|
|
|
8
8
|
//#region src/v1/providers/firestore.ts
|
|
9
9
|
var firestore_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
@@ -35,8 +35,8 @@ const defaultDatabase = "(default)";
|
|
|
35
35
|
* collection is named "users" and the document is named "Ada", then the
|
|
36
36
|
* path is "/users/Ada".
|
|
37
37
|
*/
|
|
38
|
-
function document(path
|
|
39
|
-
return _documentWithOptions(path
|
|
38
|
+
function document(path) {
|
|
39
|
+
return _documentWithOptions(path, {});
|
|
40
40
|
}
|
|
41
41
|
function namespace(namespace$1) {
|
|
42
42
|
return _namespaceWithOptions(namespace$1, {});
|
|
@@ -53,8 +53,8 @@ function _namespaceWithOptions(namespace$1, options) {
|
|
|
53
53
|
return _databaseWithOptions(defaultDatabase, options).namespace(namespace$1);
|
|
54
54
|
}
|
|
55
55
|
/** @internal */
|
|
56
|
-
function _documentWithOptions(path
|
|
57
|
-
return _databaseWithOptions(defaultDatabase, options).document(path
|
|
56
|
+
function _documentWithOptions(path, options) {
|
|
57
|
+
return _databaseWithOptions(defaultDatabase, options).document(path);
|
|
58
58
|
}
|
|
59
59
|
var DatabaseBuilder = class {
|
|
60
60
|
constructor(database$1, options) {
|
|
@@ -64,8 +64,8 @@ var DatabaseBuilder = class {
|
|
|
64
64
|
namespace(namespace$1) {
|
|
65
65
|
return new NamespaceBuilder(this.database, this.options, namespace$1);
|
|
66
66
|
}
|
|
67
|
-
document(path
|
|
68
|
-
return new NamespaceBuilder(this.database, this.options).document(path
|
|
67
|
+
document(path) {
|
|
68
|
+
return new NamespaceBuilder(this.database, this.options).document(path);
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
var NamespaceBuilder = class {
|
|
@@ -74,14 +74,24 @@ var NamespaceBuilder = class {
|
|
|
74
74
|
this.options = options;
|
|
75
75
|
this.namespace = namespace$1;
|
|
76
76
|
}
|
|
77
|
-
document(path
|
|
78
|
-
|
|
77
|
+
document(path) {
|
|
78
|
+
const triggerResource = () => {
|
|
79
79
|
if (!process.env.GCLOUD_PROJECT) {
|
|
80
80
|
throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
let project = require_params_index.projectID;
|
|
83
|
+
if (process.env.GCLOUD_PROJECT && process.env.FUNCTIONS_CONTROL_API !== "true") {
|
|
84
|
+
project = process.env.GCLOUD_PROJECT;
|
|
85
|
+
}
|
|
86
|
+
let nsPart = "";
|
|
87
|
+
if (this.namespace instanceof require_params_types.Expression) {
|
|
88
|
+
nsPart = new require_params_types.CompareExpression("==", this.namespace, "").thenElse("", require_params_index.expr`@${this.namespace}`);
|
|
89
|
+
} else if (this.namespace) {
|
|
90
|
+
nsPart = `@${this.namespace}`;
|
|
91
|
+
}
|
|
92
|
+
return require_params_index.expr`projects/${project}/databases/${this.database}/documents${nsPart}/${path}`;
|
|
93
|
+
};
|
|
94
|
+
return new DocumentBuilder(triggerResource, this.options);
|
|
85
95
|
}
|
|
86
96
|
};
|
|
87
97
|
function snapshotConstructor(event) {
|
|
@@ -94,6 +104,7 @@ function changeConstructor(raw) {
|
|
|
94
104
|
return require_common_change.Change.fromObjects(beforeSnapshotConstructor(raw), snapshotConstructor(raw));
|
|
95
105
|
}
|
|
96
106
|
var DocumentBuilder = class {
|
|
107
|
+
/** @internal */
|
|
97
108
|
constructor(triggerResource, options) {
|
|
98
109
|
this.triggerResource = triggerResource;
|
|
99
110
|
this.options = options;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CloudFunction, EventContext } from "../cloud-functions";
|
|
2
2
|
import { DeploymentOptions, ScheduleRetryConfig } from "../function-configuration";
|
|
3
|
+
import { Expression } from "../../params/types";
|
|
3
4
|
/**
|
|
4
5
|
* Registers a Cloud Function triggered when a Google Cloud Pub/Sub message
|
|
5
6
|
* is sent to a specified topic.
|
|
@@ -7,7 +8,7 @@ import { DeploymentOptions, ScheduleRetryConfig } from "../function-configuratio
|
|
|
7
8
|
* @param topic - The Pub/Sub topic to watch for message events.
|
|
8
9
|
* @returns Pub/Sub topic builder interface.
|
|
9
10
|
*/
|
|
10
|
-
export declare function topic(topic: string): TopicBuilder;
|
|
11
|
+
export declare function topic(topic: string | Expression<string>): TopicBuilder;
|
|
11
12
|
/**
|
|
12
13
|
* The Google Cloud Pub/Sub topic builder.
|
|
13
14
|
*
|
|
@@ -17,7 +18,7 @@ export declare class TopicBuilder {
|
|
|
17
18
|
private triggerResource;
|
|
18
19
|
private options;
|
|
19
20
|
/** @hidden */
|
|
20
|
-
constructor(triggerResource: () => string
|
|
21
|
+
constructor(triggerResource: () => string | Expression<string>, options: DeploymentOptions);
|
|
21
22
|
/**
|
|
22
23
|
* Event handler that fires every time a Cloud Pub/Sub message is
|
|
23
24
|
* published.
|
|
@@ -34,7 +35,7 @@ export declare class TopicBuilder {
|
|
|
34
35
|
* @param schedule - The schedule, in Unix Crontab or AppEngine syntax.
|
|
35
36
|
* @returns ScheduleBuilder interface.
|
|
36
37
|
*/
|
|
37
|
-
export declare function schedule(schedule: string): ScheduleBuilder;
|
|
38
|
+
export declare function schedule(schedule: string | Expression<string>): ScheduleBuilder;
|
|
38
39
|
/**
|
|
39
40
|
* The builder for scheduled functions, which are powered by
|
|
40
41
|
* Google Pub/Sub and Cloud Scheduler. Describes the Cloud Scheduler
|
|
@@ -48,7 +49,7 @@ export declare class ScheduleBuilder {
|
|
|
48
49
|
private triggerResource;
|
|
49
50
|
private options;
|
|
50
51
|
/** @hidden */
|
|
51
|
-
constructor(triggerResource: () => string
|
|
52
|
+
constructor(triggerResource: () => string | Expression<string>, options: DeploymentOptions);
|
|
52
53
|
retryConfig(config: ScheduleRetryConfig): ScheduleBuilder;
|
|
53
54
|
timeZone(timeZone: string): ScheduleBuilder;
|
|
54
55
|
/**
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_params_types = require('../../params/types.js');
|
|
3
|
+
const require_params_index = require('../../params/index.js');
|
|
2
4
|
const require_v1_cloud_functions = require('../cloud-functions.js');
|
|
3
5
|
|
|
4
6
|
//#region src/v1/providers/pubsub.ts
|
|
@@ -29,15 +31,16 @@ function topic(topic$1) {
|
|
|
29
31
|
}
|
|
30
32
|
/** @internal */
|
|
31
33
|
function _topicWithOptions(topic$1, options) {
|
|
32
|
-
if (topic$1.indexOf("/") !== -1) {
|
|
34
|
+
if (typeof topic$1 === "string" && topic$1.indexOf("/") !== -1) {
|
|
33
35
|
throw new Error("Topic name may not have a /");
|
|
34
36
|
}
|
|
35
|
-
|
|
37
|
+
const triggerResource = () => {
|
|
36
38
|
if (!process.env.GCLOUD_PROJECT) {
|
|
37
39
|
throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
|
38
40
|
}
|
|
39
|
-
return `projects/${process.env.GCLOUD_PROJECT}/topics/${topic$1}`;
|
|
40
|
-
}
|
|
41
|
+
return require_params_index.expr`projects/${process.env.GCLOUD_PROJECT}/topics/${topic$1}`;
|
|
42
|
+
};
|
|
43
|
+
return new TopicBuilder(triggerResource, options);
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
46
|
* The Google Cloud Pub/Sub topic builder.
|
|
@@ -89,7 +92,7 @@ function _scheduleWithOptions(schedule$1, options) {
|
|
|
89
92
|
};
|
|
90
93
|
return new ScheduleBuilder(triggerResource, {
|
|
91
94
|
...options,
|
|
92
|
-
schedule: { schedule: schedule$1 }
|
|
95
|
+
schedule: { schedule: schedule$1 instanceof require_params_types.Expression ? schedule$1.toCEL() : schedule$1 }
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CloudFunction, EventContext } from "../cloud-functions";
|
|
2
|
+
import { Expression } from "../../params/types";
|
|
2
3
|
/**
|
|
3
4
|
* Registers a Cloud Function scoped to a specific storage bucket.
|
|
4
5
|
*
|
|
@@ -7,7 +8,7 @@ import { CloudFunction, EventContext } from "../cloud-functions";
|
|
|
7
8
|
*
|
|
8
9
|
* @returns Storage bucket builder interface.
|
|
9
10
|
*/
|
|
10
|
-
export declare function bucket(bucket?: string): BucketBuilder;
|
|
11
|
+
export declare function bucket(bucket?: string | Expression<string>): BucketBuilder;
|
|
11
12
|
/**
|
|
12
13
|
* Registers a Cloud Function scoped to the default storage bucket for the
|
|
13
14
|
* project.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_params_index = require('../../params/index.js');
|
|
2
3
|
const require_common_config = require('../../common/config.js');
|
|
3
4
|
const require_v1_cloud_functions = require('../cloud-functions.js');
|
|
4
5
|
|
|
@@ -40,14 +41,14 @@ function object() {
|
|
|
40
41
|
/** @internal */
|
|
41
42
|
function _bucketWithOptions(options, bucket$1) {
|
|
42
43
|
const resourceGetter = () => {
|
|
43
|
-
|
|
44
|
-
if (!
|
|
44
|
+
const bucketName = bucket$1 || require_common_config.firebaseConfig().storageBucket;
|
|
45
|
+
if (!bucketName) {
|
|
45
46
|
throw new Error("Missing bucket name. If you are unit testing, please provide a bucket name" + " through `functions.storage.bucket(bucketName)`, or set process.env.FIREBASE_CONFIG.");
|
|
46
47
|
}
|
|
47
|
-
if (!/^[a-z\d][a-z\d\\._-]{1,230}[a-z\d]$/.test(
|
|
48
|
-
throw new Error(`Invalid bucket name ${
|
|
48
|
+
if (typeof bucketName === "string" && !/^[a-z\d][a-z\d\\._-]{1,230}[a-z\d]$/.test(bucketName)) {
|
|
49
|
+
throw new Error(`Invalid bucket name ${bucketName}`);
|
|
49
50
|
}
|
|
50
|
-
return `projects/_/buckets/${
|
|
51
|
+
return require_params_index.expr`projects/_/buckets/${bucketName}`;
|
|
51
52
|
};
|
|
52
53
|
return new BucketBuilder(resourceGetter, options);
|
|
53
54
|
}
|