firebase-functions 7.2.0-rc.0 → 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/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/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/package.json +1 -1
package/lib/esm/params/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __export } from "../_virtual/rolldown_runtime.mjs";
|
|
2
|
-
import { BUCKET_PICKER, BooleanParam, Expression, FloatParam, IntParam, InternalExpression, JsonSecretParam, ListParam, SecretParam, StringParam, multiSelect, select } from "./types.mjs";
|
|
2
|
+
import { BUCKET_PICKER, BooleanParam, Expression, FloatParam, IntParam, InternalExpression, InterpolationExpression, JsonSecretParam, ListParam, SecretParam, StringParam, multiSelect, select } from "./types.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/params/index.ts
|
|
5
5
|
var params_exports = /* @__PURE__ */ __export({
|
|
@@ -15,6 +15,7 @@ var params_exports = /* @__PURE__ */ __export({
|
|
|
15
15
|
defineList: () => defineList,
|
|
16
16
|
defineSecret: () => defineSecret,
|
|
17
17
|
defineString: () => defineString,
|
|
18
|
+
expr: () => expr,
|
|
18
19
|
gcloudProject: () => gcloudProject,
|
|
19
20
|
multiSelect: () => multiSelect,
|
|
20
21
|
projectID: () => projectID,
|
|
@@ -59,23 +60,23 @@ function clearParams() {
|
|
|
59
60
|
* A built-in parameter that resolves to the default RTDB database URL associated
|
|
60
61
|
* with the project, without prompting the deployer. Empty string if none exists.
|
|
61
62
|
*/
|
|
62
|
-
const databaseURL = new InternalExpression("DATABASE_URL", (env) => JSON.parse(env.FIREBASE_CONFIG)?.databaseURL || "");
|
|
63
|
+
const databaseURL = new InternalExpression("DATABASE_URL", (env) => JSON.parse(env.FIREBASE_CONFIG || "{}")?.databaseURL || "");
|
|
63
64
|
/**
|
|
64
65
|
* A built-in parameter that resolves to the Cloud project ID associated with
|
|
65
66
|
* the project, without prompting the deployer.
|
|
66
67
|
*/
|
|
67
|
-
const projectID = new InternalExpression("PROJECT_ID", (env) => JSON.parse(env.FIREBASE_CONFIG)?.projectId || "");
|
|
68
|
+
const projectID = new InternalExpression("PROJECT_ID", (env) => JSON.parse(env.FIREBASE_CONFIG || "{}")?.projectId || "");
|
|
68
69
|
/**
|
|
69
70
|
* A built-in parameter that resolves to the Cloud project ID, without prompting
|
|
70
71
|
* the deployer.
|
|
71
72
|
*/
|
|
72
|
-
const gcloudProject = new InternalExpression("GCLOUD_PROJECT", (env) => JSON.parse(env.FIREBASE_CONFIG)?.projectId || "");
|
|
73
|
+
const gcloudProject = new InternalExpression("GCLOUD_PROJECT", (env) => JSON.parse(env.FIREBASE_CONFIG || "{}")?.projectId || "");
|
|
73
74
|
/**
|
|
74
75
|
* A builtin parameter that resolves to the Cloud storage bucket associated
|
|
75
76
|
* with the function, without prompting the deployer. Empty string if not
|
|
76
77
|
* defined.
|
|
77
78
|
*/
|
|
78
|
-
const storageBucket = new InternalExpression("STORAGE_BUCKET", (env) => JSON.parse(env.FIREBASE_CONFIG)?.storageBucket || "");
|
|
79
|
+
const storageBucket = new InternalExpression("STORAGE_BUCKET", (env) => JSON.parse(env.FIREBASE_CONFIG || "{}")?.storageBucket || "");
|
|
79
80
|
/**
|
|
80
81
|
* Declares a secret param, that will persist values only in Cloud Secret Manager.
|
|
81
82
|
* Secrets are stored internally as bytestrings. Use `ParamOptions.as` to provide type
|
|
@@ -84,8 +85,8 @@ const storageBucket = new InternalExpression("STORAGE_BUCKET", (env) => JSON.par
|
|
|
84
85
|
* @param name The name of the environment variable to use to load the parameter.
|
|
85
86
|
* @returns A parameter with a `string` return type for `.value`.
|
|
86
87
|
*/
|
|
87
|
-
function defineSecret(name) {
|
|
88
|
-
const param = new SecretParam(name);
|
|
88
|
+
function defineSecret(name, options = {}) {
|
|
89
|
+
const param = new SecretParam(name, options);
|
|
89
90
|
registerParam(param);
|
|
90
91
|
return param;
|
|
91
92
|
}
|
|
@@ -101,8 +102,8 @@ function defineSecret(name) {
|
|
|
101
102
|
* @returns A parameter whose `.value()` method returns the parsed JSON object.
|
|
102
103
|
* ```
|
|
103
104
|
*/
|
|
104
|
-
function defineJsonSecret(name) {
|
|
105
|
-
const param = new JsonSecretParam(name);
|
|
105
|
+
function defineJsonSecret(name, options = {}) {
|
|
106
|
+
const param = new JsonSecretParam(name, options);
|
|
106
107
|
registerParam(param);
|
|
107
108
|
return param;
|
|
108
109
|
}
|
|
@@ -168,6 +169,19 @@ function defineList(name, options = {}) {
|
|
|
168
169
|
registerParam(param);
|
|
169
170
|
return param;
|
|
170
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Creates an Expression representing a string, which can interpolate
|
|
174
|
+
* other Expressions into it using template literal syntax.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```
|
|
178
|
+
* const topicParam = defineString('TOPIC');
|
|
179
|
+
* const topicExpr = expr`projects/my-project/topics/${topicParam}`;
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
function expr(strings, ...values) {
|
|
183
|
+
return new InterpolationExpression(strings, values);
|
|
184
|
+
}
|
|
171
185
|
|
|
172
186
|
//#endregion
|
|
173
|
-
export { BUCKET_PICKER, Expression, clearParams, databaseURL, declaredParams, defineBoolean, defineFloat, defineInt, defineJsonSecret, defineList, defineSecret, defineString, gcloudProject, multiSelect, params_exports, projectID, select, storageBucket };
|
|
187
|
+
export { BUCKET_PICKER, Expression, clearParams, databaseURL, declaredParams, defineBoolean, defineFloat, defineInt, defineJsonSecret, defineList, defineSecret, defineString, expr, gcloudProject, multiSelect, params_exports, projectID, select, storageBucket };
|
package/lib/esm/params/types.mjs
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
|
}
|
|
@@ -410,4 +460,4 @@ var ListParam = class extends Param {
|
|
|
410
460
|
};
|
|
411
461
|
|
|
412
462
|
//#endregion
|
|
413
|
-
export { BUCKET_PICKER, BooleanParam, CompareExpression, Expression, FloatParam, IntParam, InternalExpression, JsonSecretParam, ListParam, Param, SecretParam, StringParam, TernaryExpression, multiSelect, select };
|
|
463
|
+
export { BUCKET_PICKER, BooleanParam, CompareExpression, Expression, FloatParam, IntParam, InternalExpression, InterpolationExpression, JsonSecretParam, ListParam, Param, SecretParam, StringParam, TernaryExpression, TransformedStringExpression, celOf, multiSelect, select, transform, valueOf };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { warn } from "../logger/index.mjs";
|
|
2
|
+
import { Expression, celOf, valueOf } from "../params/types.mjs";
|
|
2
3
|
import { RESET_VALUE, ResetValue } from "../common/options.mjs";
|
|
3
4
|
import { initV1Endpoint, initV1ScheduleTrigger } from "../runtime/manifest.mjs";
|
|
4
5
|
import { Change } from "../common/change.mjs";
|
|
@@ -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: 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 = initV1ScheduleTrigger(options.schedule.schedule, options);
|
|
86
|
+
endpoint.scheduleTrigger = initV1ScheduleTrigger(celOf(options.schedule.schedule), options);
|
|
85
87
|
copyIfPresent(endpoint.scheduleTrigger, options.schedule, "timeZone");
|
|
88
|
+
if (endpoint.scheduleTrigger.timeZone instanceof Expression) {
|
|
89
|
+
endpoint.scheduleTrigger.timeZone = endpoint.scheduleTrigger.timeZone.toCEL();
|
|
90
|
+
}
|
|
86
91
|
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: 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 = valueOf(triggerResourceGetter());
|
|
114
119
|
const wildcards = triggerResource.match(WILDCARD_REGEX);
|
|
115
120
|
const params = {};
|
|
116
121
|
const eventResourceParts = context?.resource?.name?.split?.("/");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { expr } from "../../params/index.mjs";
|
|
2
3
|
import { makeCloudFunction } from "../cloud-functions.mjs";
|
|
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 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;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { transform } from "../../params/types.mjs";
|
|
3
|
+
import { expr } from "../../params/index.mjs";
|
|
2
4
|
import { firebaseConfig } from "../../common/config.mjs";
|
|
3
5
|
import { getApp } from "../../common/app.mjs";
|
|
4
6
|
import { makeCloudFunction } from "../cloud-functions.mjs";
|
|
@@ -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 =
|
|
100
|
-
return new RefBuilder(() => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
|
|
101
|
+
const normalized = transform(path, normalizePath);
|
|
102
|
+
return new RefBuilder(() => 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 =
|
|
108
|
+
const normalized = transform(path, normalizePath);
|
|
107
109
|
const databaseURL = firebaseConfig().databaseURL;
|
|
108
110
|
if (!databaseURL) {
|
|
109
111
|
throw new Error("Missing expected firebase config value databaseURL, " + "config is actually" + JSON.stringify(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 expr`projects/_/instances/${instance$1}/refs/${normalized}`;
|
|
125
127
|
};
|
|
126
128
|
return new RefBuilder(resourceGetter, options);
|
|
127
129
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { CompareExpression, Expression } from "../../params/types.mjs";
|
|
3
|
+
import { expr, projectID } from "../../params/index.mjs";
|
|
2
4
|
import { Change } from "../../common/change.mjs";
|
|
3
5
|
import { makeCloudFunction } from "../cloud-functions.mjs";
|
|
4
6
|
import { createBeforeSnapshotFromJson, createSnapshotFromJson } from "../../common/providers/firestore.mjs";
|
|
5
|
-
import { posix } from "path";
|
|
6
7
|
|
|
7
8
|
//#region src/v1/providers/firestore.ts
|
|
8
9
|
var firestore_exports = /* @__PURE__ */ __export({
|
|
@@ -74,13 +75,23 @@ var NamespaceBuilder = class {
|
|
|
74
75
|
this.namespace = namespace$1;
|
|
75
76
|
}
|
|
76
77
|
document(path) {
|
|
77
|
-
|
|
78
|
+
const triggerResource = () => {
|
|
78
79
|
if (!process.env.GCLOUD_PROJECT) {
|
|
79
80
|
throw new Error("process.env.GCLOUD_PROJECT is not set.");
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
let project = 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 Expression) {
|
|
88
|
+
nsPart = new CompareExpression("==", this.namespace, "").thenElse("", expr`@${this.namespace}`);
|
|
89
|
+
} else if (this.namespace) {
|
|
90
|
+
nsPart = `@${this.namespace}`;
|
|
91
|
+
}
|
|
92
|
+
return expr`projects/${project}/databases/${this.database}/documents${nsPart}/${path}`;
|
|
93
|
+
};
|
|
94
|
+
return new DocumentBuilder(triggerResource, this.options);
|
|
84
95
|
}
|
|
85
96
|
};
|
|
86
97
|
function snapshotConstructor(event) {
|
|
@@ -93,6 +104,7 @@ function changeConstructor(raw) {
|
|
|
93
104
|
return Change.fromObjects(beforeSnapshotConstructor(raw), snapshotConstructor(raw));
|
|
94
105
|
}
|
|
95
106
|
var DocumentBuilder = class {
|
|
107
|
+
/** @internal */
|
|
96
108
|
constructor(triggerResource, options) {
|
|
97
109
|
this.triggerResource = triggerResource;
|
|
98
110
|
this.options = options;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { Expression } from "../../params/types.mjs";
|
|
3
|
+
import { expr } from "../../params/index.mjs";
|
|
2
4
|
import { makeCloudFunction } from "../cloud-functions.mjs";
|
|
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 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 Expression ? schedule$1.toCEL() : schedule$1 }
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { expr } from "../../params/index.mjs";
|
|
2
3
|
import { firebaseConfig } from "../../common/config.mjs";
|
|
3
4
|
import { makeCloudFunction } from "../cloud-functions.mjs";
|
|
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 || 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 expr`projects/_/buckets/${bucketName}`;
|
|
51
52
|
};
|
|
52
53
|
return new BucketBuilder(resourceGetter, options);
|
|
53
54
|
}
|
package/lib/params/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @hidden
|
|
3
3
|
* @alpha
|
|
4
4
|
*/
|
|
5
|
-
import { BooleanParam, Expression, IntParam, Param, ParamOptions, SecretParam, JsonSecretParam, StringParam, ListParam } from "./types";
|
|
5
|
+
import { BooleanParam, Expression, IntParam, Param, ParamOptions, SecretParam, JsonSecretParam, StringParam, ListParam, SecretParamOptions } from "./types";
|
|
6
6
|
export { BUCKET_PICKER, select, multiSelect } from "./types";
|
|
7
7
|
export type { TextInput, SelectInput, SelectOptions, MultiSelectInput, Param, SecretParam, JsonSecretParam, StringParam, BooleanParam, IntParam, ListParam, } from "./types";
|
|
8
8
|
export { Expression };
|
|
9
|
-
export type { ParamOptions };
|
|
9
|
+
export type { ParamOptions, SecretParamOptions };
|
|
10
10
|
type SecretOrExpr = Param<any> | SecretParam | JsonSecretParam<any>;
|
|
11
11
|
export declare const declaredParams: SecretOrExpr[];
|
|
12
12
|
/**
|
|
@@ -38,7 +38,7 @@ export declare const storageBucket: Param<string>;
|
|
|
38
38
|
* @param name The name of the environment variable to use to load the parameter.
|
|
39
39
|
* @returns A parameter with a `string` return type for `.value`.
|
|
40
40
|
*/
|
|
41
|
-
export declare function defineSecret(name: string): SecretParam;
|
|
41
|
+
export declare function defineSecret(name: string, options?: SecretParamOptions): SecretParam;
|
|
42
42
|
/**
|
|
43
43
|
* Declares a secret parameter that retrieves a structured JSON object in Cloud Secret Manager.
|
|
44
44
|
* This is useful for managing groups of related configuration values, such as all settings
|
|
@@ -51,7 +51,7 @@ export declare function defineSecret(name: string): SecretParam;
|
|
|
51
51
|
* @returns A parameter whose `.value()` method returns the parsed JSON object.
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
export declare function defineJsonSecret<T = any>(name: string): JsonSecretParam<T>;
|
|
54
|
+
export declare function defineJsonSecret<T = any>(name: string, options?: SecretParamOptions): JsonSecretParam<T>;
|
|
55
55
|
/**
|
|
56
56
|
* Declare a string parameter.
|
|
57
57
|
*
|
|
@@ -84,3 +84,14 @@ export declare function defineInt(name: string, options?: ParamOptions<number>):
|
|
|
84
84
|
* @returns A parameter with a `string[]` return type for `.value`.
|
|
85
85
|
*/
|
|
86
86
|
export declare function defineList(name: string, options?: ParamOptions<string[]>): ListParam;
|
|
87
|
+
/**
|
|
88
|
+
* Creates an Expression representing a string, which can interpolate
|
|
89
|
+
* other Expressions into it using template literal syntax.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```
|
|
93
|
+
* const topicParam = defineString('TOPIC');
|
|
94
|
+
* const topicExpr = expr`projects/my-project/topics/${topicParam}`;
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function expr(strings: TemplateStringsArray, ...values: (string | Expression<string>)[]): Expression<string>;
|
package/lib/params/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var params_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
|
15
15
|
defineList: () => defineList,
|
|
16
16
|
defineSecret: () => defineSecret,
|
|
17
17
|
defineString: () => defineString,
|
|
18
|
+
expr: () => expr,
|
|
18
19
|
gcloudProject: () => gcloudProject,
|
|
19
20
|
multiSelect: () => require_params_types.multiSelect,
|
|
20
21
|
projectID: () => projectID,
|
|
@@ -59,23 +60,23 @@ function clearParams() {
|
|
|
59
60
|
* A built-in parameter that resolves to the default RTDB database URL associated
|
|
60
61
|
* with the project, without prompting the deployer. Empty string if none exists.
|
|
61
62
|
*/
|
|
62
|
-
const databaseURL = new require_params_types.InternalExpression("DATABASE_URL", (env) => JSON.parse(env.FIREBASE_CONFIG)?.databaseURL || "");
|
|
63
|
+
const databaseURL = new require_params_types.InternalExpression("DATABASE_URL", (env) => JSON.parse(env.FIREBASE_CONFIG || "{}")?.databaseURL || "");
|
|
63
64
|
/**
|
|
64
65
|
* A built-in parameter that resolves to the Cloud project ID associated with
|
|
65
66
|
* the project, without prompting the deployer.
|
|
66
67
|
*/
|
|
67
|
-
const projectID = new require_params_types.InternalExpression("PROJECT_ID", (env) => JSON.parse(env.FIREBASE_CONFIG)?.projectId || "");
|
|
68
|
+
const projectID = new require_params_types.InternalExpression("PROJECT_ID", (env) => JSON.parse(env.FIREBASE_CONFIG || "{}")?.projectId || "");
|
|
68
69
|
/**
|
|
69
70
|
* A built-in parameter that resolves to the Cloud project ID, without prompting
|
|
70
71
|
* the deployer.
|
|
71
72
|
*/
|
|
72
|
-
const gcloudProject = new require_params_types.InternalExpression("GCLOUD_PROJECT", (env) => JSON.parse(env.FIREBASE_CONFIG)?.projectId || "");
|
|
73
|
+
const gcloudProject = new require_params_types.InternalExpression("GCLOUD_PROJECT", (env) => JSON.parse(env.FIREBASE_CONFIG || "{}")?.projectId || "");
|
|
73
74
|
/**
|
|
74
75
|
* A builtin parameter that resolves to the Cloud storage bucket associated
|
|
75
76
|
* with the function, without prompting the deployer. Empty string if not
|
|
76
77
|
* defined.
|
|
77
78
|
*/
|
|
78
|
-
const storageBucket = new require_params_types.InternalExpression("STORAGE_BUCKET", (env) => JSON.parse(env.FIREBASE_CONFIG)?.storageBucket || "");
|
|
79
|
+
const storageBucket = new require_params_types.InternalExpression("STORAGE_BUCKET", (env) => JSON.parse(env.FIREBASE_CONFIG || "{}")?.storageBucket || "");
|
|
79
80
|
/**
|
|
80
81
|
* Declares a secret param, that will persist values only in Cloud Secret Manager.
|
|
81
82
|
* Secrets are stored internally as bytestrings. Use `ParamOptions.as` to provide type
|
|
@@ -84,8 +85,8 @@ const storageBucket = new require_params_types.InternalExpression("STORAGE_BUCKE
|
|
|
84
85
|
* @param name The name of the environment variable to use to load the parameter.
|
|
85
86
|
* @returns A parameter with a `string` return type for `.value`.
|
|
86
87
|
*/
|
|
87
|
-
function defineSecret(name) {
|
|
88
|
-
const param = new require_params_types.SecretParam(name);
|
|
88
|
+
function defineSecret(name, options = {}) {
|
|
89
|
+
const param = new require_params_types.SecretParam(name, options);
|
|
89
90
|
registerParam(param);
|
|
90
91
|
return param;
|
|
91
92
|
}
|
|
@@ -101,8 +102,8 @@ function defineSecret(name) {
|
|
|
101
102
|
* @returns A parameter whose `.value()` method returns the parsed JSON object.
|
|
102
103
|
* ```
|
|
103
104
|
*/
|
|
104
|
-
function defineJsonSecret(name) {
|
|
105
|
-
const param = new require_params_types.JsonSecretParam(name);
|
|
105
|
+
function defineJsonSecret(name, options = {}) {
|
|
106
|
+
const param = new require_params_types.JsonSecretParam(name, options);
|
|
106
107
|
registerParam(param);
|
|
107
108
|
return param;
|
|
108
109
|
}
|
|
@@ -168,6 +169,19 @@ function defineList(name, options = {}) {
|
|
|
168
169
|
registerParam(param);
|
|
169
170
|
return param;
|
|
170
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Creates an Expression representing a string, which can interpolate
|
|
174
|
+
* other Expressions into it using template literal syntax.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```
|
|
178
|
+
* const topicParam = defineString('TOPIC');
|
|
179
|
+
* const topicExpr = expr`projects/my-project/topics/${topicParam}`;
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
function expr(strings, ...values) {
|
|
183
|
+
return new require_params_types.InterpolationExpression(strings, values);
|
|
184
|
+
}
|
|
171
185
|
|
|
172
186
|
//#endregion
|
|
173
187
|
exports.BUCKET_PICKER = require_params_types.BUCKET_PICKER;
|
|
@@ -182,6 +196,7 @@ exports.defineJsonSecret = defineJsonSecret;
|
|
|
182
196
|
exports.defineList = defineList;
|
|
183
197
|
exports.defineSecret = defineSecret;
|
|
184
198
|
exports.defineString = defineString;
|
|
199
|
+
exports.expr = expr;
|
|
185
200
|
exports.gcloudProject = gcloudProject;
|
|
186
201
|
exports.multiSelect = require_params_types.multiSelect;
|
|
187
202
|
Object.defineProperty(exports, 'params_exports', {
|
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;
|
|
@@ -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
|
}
|