firebase-functions 3.24.1 → 4.0.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/README.md +7 -9
- package/lib/bin/firebase-functions.js +13 -15
- package/lib/common/app.d.ts +14 -0
- package/lib/common/app.js +62 -0
- package/lib/common/change.d.ts +0 -5
- package/lib/common/change.js +5 -7
- package/lib/common/config.d.ts +6 -0
- package/lib/common/config.js +49 -0
- package/lib/common/debug.js +2 -2
- package/lib/common/encoding.d.ts +0 -8
- package/lib/common/encoding.js +6 -29
- package/lib/common/options.d.ts +14 -0
- package/lib/common/options.js +44 -0
- package/lib/common/params.d.ts +32 -0
- package/lib/common/params.js +23 -0
- package/lib/common/providers/database.d.ts +17 -19
- package/lib/common/providers/database.js +68 -39
- package/lib/common/providers/https.d.ts +11 -52
- package/lib/common/providers/https.js +115 -110
- package/lib/common/providers/identity.d.ts +8 -8
- package/lib/common/providers/identity.js +71 -79
- package/lib/common/providers/tasks.d.ts +11 -10
- package/lib/common/providers/tasks.js +10 -9
- package/lib/common/timezone.js +538 -538
- package/lib/common/trace.d.ts +14 -0
- package/lib/common/trace.js +69 -0
- package/lib/{encoder.d.ts → common/utilities/encoder.d.ts} +0 -0
- package/lib/{encoder.js → common/utilities/encoder.js} +1 -1
- package/lib/{utilities → common/utilities}/path-pattern.d.ts +0 -0
- package/lib/{utilities → common/utilities}/path-pattern.js +17 -16
- package/lib/{utilities → common/utilities}/path.d.ts +0 -0
- package/lib/{utilities → common/utilities}/path.js +5 -7
- package/lib/{utils.d.ts → common/utilities/utils.d.ts} +1 -1
- package/lib/{utils.js → common/utilities/utils.js} +18 -12
- package/lib/logger/common.d.ts +1 -3
- package/lib/logger/common.js +9 -14
- package/lib/logger/compat.js +9 -9
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +24 -30
- package/lib/{v2/params → params}/index.d.ts +22 -9
- package/lib/{v2/params → params}/index.js +22 -14
- package/lib/params/types.d.ts +180 -0
- package/lib/params/types.js +289 -0
- package/lib/runtime/loader.js +12 -14
- package/lib/runtime/manifest.d.ts +56 -24
- package/lib/runtime/manifest.js +114 -4
- package/lib/v1/cloud-functions.d.ts +232 -0
- package/lib/v1/cloud-functions.js +205 -0
- package/lib/v1/config.d.ts +8 -0
- package/lib/v1/config.js +75 -0
- package/lib/{function-builder.d.ts → v1/function-builder.d.ts} +16 -16
- package/lib/{function-builder.js → v1/function-builder.js} +56 -46
- package/lib/v1/function-configuration.d.ts +197 -0
- package/lib/v1/function-configuration.js +70 -0
- package/lib/v1/index.d.ts +20 -0
- package/lib/{index.js → v1/index.js} +5 -10
- package/lib/{providers → v1/providers}/analytics.d.ts +5 -11
- package/lib/{providers → v1/providers}/analytics.js +49 -43
- package/lib/{providers → v1/providers}/auth.d.ts +28 -18
- package/lib/{providers → v1/providers}/auth.js +45 -34
- package/lib/{providers → v1/providers}/database.d.ts +25 -42
- package/lib/{providers → v1/providers}/database.js +46 -46
- package/lib/{providers → v1/providers}/firestore.d.ts +15 -33
- package/lib/{providers → v1/providers}/firestore.js +40 -44
- package/lib/{providers → v1/providers}/https.d.ts +3 -8
- package/lib/{providers → v1/providers}/https.js +14 -22
- package/lib/{providers → v1/providers}/pubsub.d.ts +8 -16
- package/lib/{providers → v1/providers}/pubsub.js +22 -26
- package/lib/{providers → v1/providers}/remoteConfig.d.ts +2 -11
- package/lib/{providers → v1/providers}/remoteConfig.js +9 -9
- package/lib/{providers → v1/providers}/storage.d.ts +11 -26
- package/lib/{providers → v1/providers}/storage.js +24 -29
- package/lib/{providers → v1/providers}/tasks.d.ts +6 -8
- package/lib/{providers → v1/providers}/tasks.js +12 -17
- package/lib/{providers → v1/providers}/testLab.d.ts +86 -46
- package/lib/{providers → v1/providers}/testLab.js +14 -14
- package/lib/v2/core.d.ts +4 -5
- package/lib/v2/index.d.ts +16 -14
- package/lib/v2/index.js +5 -1
- package/lib/v2/options.d.ts +52 -32
- package/lib/v2/options.js +32 -47
- package/lib/v2/providers/alerts/alerts.d.ts +20 -18
- package/lib/v2/providers/alerts/alerts.js +9 -6
- package/lib/v2/providers/alerts/appDistribution.d.ts +28 -26
- package/lib/v2/providers/alerts/appDistribution.js +8 -7
- package/lib/v2/providers/alerts/billing.d.ts +5 -5
- package/lib/v2/providers/alerts/billing.js +5 -4
- package/lib/v2/providers/alerts/crashlytics.d.ts +32 -30
- package/lib/v2/providers/alerts/crashlytics.js +10 -9
- package/lib/v2/providers/alerts/index.d.ts +5 -5
- package/lib/v2/providers/alerts/performance.d.ts +3 -3
- package/lib/v2/providers/alerts/performance.js +5 -7
- package/lib/v2/providers/database.d.ts +41 -38
- package/lib/v2/providers/database.js +22 -17
- package/lib/v2/providers/eventarc.d.ts +25 -23
- package/lib/v2/providers/eventarc.js +10 -7
- package/lib/v2/providers/https.d.ts +43 -33
- package/lib/v2/providers/https.js +18 -56
- package/lib/v2/providers/identity.d.ts +25 -23
- package/lib/v2/providers/identity.js +10 -7
- package/lib/v2/providers/pubsub.d.ts +25 -23
- package/lib/v2/providers/pubsub.js +11 -27
- package/lib/v2/providers/remoteConfig.d.ts +63 -0
- package/lib/v2/providers/remoteConfig.js +65 -0
- package/lib/v2/providers/scheduler.d.ts +14 -12
- package/lib/v2/providers/scheduler.js +16 -14
- package/lib/v2/providers/storage.d.ts +32 -30
- package/lib/v2/providers/storage.js +16 -32
- package/lib/v2/providers/tasks.d.ts +30 -26
- package/lib/v2/providers/tasks.js +14 -31
- package/lib/v2/providers/testLab.d.ts +110 -0
- package/lib/v2/providers/testLab.js +65 -0
- package/lib/v2/trace.d.ts +4 -0
- package/lib/v2/trace.js +21 -0
- package/package.json +61 -66
- package/lib/apps.d.ts +0 -35
- package/lib/apps.js +0 -112
- package/lib/cloud-functions.d.ts +0 -231
- package/lib/cloud-functions.js +0 -251
- package/lib/config.d.ts +0 -24
- package/lib/config.js +0 -117
- package/lib/function-configuration.d.ts +0 -108
- package/lib/function-configuration.js +0 -71
- package/lib/handler-builder.d.ts +0 -256
- package/lib/handler-builder.js +0 -349
- package/lib/index.d.ts +0 -19
- package/lib/setup.d.ts +0 -1
- package/lib/setup.js +0 -60
- package/lib/v2/params/types.d.ts +0 -118
- package/lib/v2/params/types.js +0 -196
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
export declare abstract class Expression<T extends string | number | boolean | string[]> {
|
|
2
|
+
/** Returns the Expression's runtime value, based on the CLI's resolution of params. */
|
|
3
|
+
value(): T;
|
|
4
|
+
/** Returns the Expression's representation as a braced CEL expression. */
|
|
5
|
+
toCEL(): string;
|
|
6
|
+
toJSON(): string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A CEL expression corresponding to a ternary operator, e.g {{ cond ? ifTrue : ifFalse }}
|
|
10
|
+
*/
|
|
11
|
+
export declare class TernaryExpression<T extends string | number | boolean | string[]> extends Expression<T> {
|
|
12
|
+
private readonly test;
|
|
13
|
+
private readonly ifTrue;
|
|
14
|
+
private readonly ifFalse;
|
|
15
|
+
constructor(test: Expression<boolean>, ifTrue: T | Expression<T>, ifFalse: T | Expression<T>);
|
|
16
|
+
toString(): string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A CEL expression that evaluates to boolean true or false based on a comparison
|
|
20
|
+
* between the value of another expression and a literal of that same type.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CompareExpression<T extends string | number | boolean | string[]> extends Expression<boolean> {
|
|
23
|
+
cmp: "==" | "!=" | ">" | ">=" | "<" | "<=";
|
|
24
|
+
lhs: Expression<T>;
|
|
25
|
+
rhs: T | Expression<T>;
|
|
26
|
+
constructor(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", lhs: Expression<T>, rhs: T | Expression<T>);
|
|
27
|
+
toString(): string;
|
|
28
|
+
/** Returns a TernaryExpression which can resolve to one of two values, based on the resolution of this comparison. */
|
|
29
|
+
then<retT extends string | number | boolean | string[]>(ifTrue: retT | Expression<retT>, ifFalse: retT | Expression<retT>): TernaryExpression<retT>;
|
|
30
|
+
}
|
|
31
|
+
/** @hidden */
|
|
32
|
+
declare type ParamValueType = "string" | "list" | "boolean" | "int" | "float" | "secret";
|
|
33
|
+
declare type ParamInput<T> = {
|
|
34
|
+
text: TextInput<T>;
|
|
35
|
+
} | {
|
|
36
|
+
select: SelectInput<T>;
|
|
37
|
+
} | {
|
|
38
|
+
resource: ResourceInput;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Specifies that a Param's value should be determined by prompting the user
|
|
42
|
+
* to type it in interactively at deploy-time. Input that does not match the
|
|
43
|
+
* provided validationRegex, if present, will be retried.
|
|
44
|
+
*/
|
|
45
|
+
export interface TextInput<T = unknown> {
|
|
46
|
+
example?: string;
|
|
47
|
+
/**
|
|
48
|
+
* A regular expression (or an escaped string to compile into a regular
|
|
49
|
+
* expression) which the prompted text must satisfy; the prompt will retry
|
|
50
|
+
* until input matching the regex is provided.
|
|
51
|
+
*/
|
|
52
|
+
validationRegex?: string | RegExp;
|
|
53
|
+
/**
|
|
54
|
+
* A custom error message to display when retrying the prompt based on input
|
|
55
|
+
* failing to conform to the validationRegex,
|
|
56
|
+
*/
|
|
57
|
+
validationErrorMessage?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Specifies that a Param's value should be determined by having the user
|
|
61
|
+
* select from a list containing all the project's resources of a certain
|
|
62
|
+
* type. Currently, only type:"storage.googleapis.com/Bucket" is supported.
|
|
63
|
+
*/
|
|
64
|
+
export interface ResourceInput {
|
|
65
|
+
resource: {
|
|
66
|
+
type: string;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Specifies that a Param's value should be determined by having the user select
|
|
71
|
+
* from a list of pre-canned options interactively at deploy-time.
|
|
72
|
+
*/
|
|
73
|
+
export interface SelectInput<T = unknown> {
|
|
74
|
+
options: Array<SelectOptions<T>>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* One of the options provided to a SelectInput, containing a value and
|
|
78
|
+
* optionally a human-readable label to display in the selection interface.
|
|
79
|
+
*/
|
|
80
|
+
export interface SelectOptions<T = unknown> {
|
|
81
|
+
label?: string;
|
|
82
|
+
value: T;
|
|
83
|
+
}
|
|
84
|
+
/** The wire representation of a Param when it's sent to the CLI. A superset of ParamOptions. */
|
|
85
|
+
export declare type ParamSpec<T extends string | number | boolean | string[]> = {
|
|
86
|
+
/** The name of the parameter which will be stored in .env files. Use UPPERCASE. */
|
|
87
|
+
name: string;
|
|
88
|
+
/** An optional default value to be used while prompting for input. Can be a literal or another parametrized expression. */
|
|
89
|
+
default?: T | Expression<T>;
|
|
90
|
+
/** An optional human-readable string to be used as a replacement for the Param's name when prompting. */
|
|
91
|
+
label?: string;
|
|
92
|
+
/** An optional long-form description of the Param to be displayed while prompting. */
|
|
93
|
+
description?: string;
|
|
94
|
+
/** The way in which the Firebase CLI will prompt for the value of this Param. Defaults to a TextInput. */
|
|
95
|
+
input?: ParamInput<T>;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Representation of parameters for the stack over the wire.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* N.B: a WireParamSpec is just a ParamSpec with default expressions converted into a CEL literal
|
|
102
|
+
*
|
|
103
|
+
* @alpha
|
|
104
|
+
*/
|
|
105
|
+
export declare type WireParamSpec<T extends string | number | boolean | string[]> = {
|
|
106
|
+
name: string;
|
|
107
|
+
default?: T | string;
|
|
108
|
+
label?: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
type: ParamValueType;
|
|
111
|
+
input?: ParamInput<T>;
|
|
112
|
+
};
|
|
113
|
+
/** Configuration options which can be used to customize the prompting behavior of a Param. */
|
|
114
|
+
export declare type ParamOptions<T extends string | number | boolean | string[]> = Omit<ParamSpec<T>, "name" | "type">;
|
|
115
|
+
/**
|
|
116
|
+
* Represents a parametrized value that will be read from .env files if present,
|
|
117
|
+
* or prompted for by the CLI if missing. Instantiate these with the defineX
|
|
118
|
+
* methods exported by the firebase-functions/params namespace.
|
|
119
|
+
*/
|
|
120
|
+
export declare abstract class Param<T extends string | number | boolean | string[]> extends Expression<T> {
|
|
121
|
+
readonly name: string;
|
|
122
|
+
readonly options: ParamOptions<T>;
|
|
123
|
+
static type: ParamValueType;
|
|
124
|
+
constructor(name: string, options?: ParamOptions<T>);
|
|
125
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
126
|
+
cmp(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", rhs: T | Expression<T>): CompareExpression<T>;
|
|
127
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
128
|
+
equals(rhs: T | Expression<T>): CompareExpression<T>;
|
|
129
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
130
|
+
notEquals(rhs: T | Expression<T>): CompareExpression<T>;
|
|
131
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
132
|
+
greaterThan(rhs: T | Expression<T>): CompareExpression<T>;
|
|
133
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
134
|
+
greaterThanOrEqualTo(rhs: T | Expression<T>): CompareExpression<T>;
|
|
135
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
136
|
+
lessThan(rhs: T | Expression<T>): CompareExpression<T>;
|
|
137
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
138
|
+
lessThanorEqualTo(rhs: T | Expression<T>): CompareExpression<T>;
|
|
139
|
+
toString(): string;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A parametrized string whose value is stored in Cloud Secret Manager
|
|
143
|
+
* instead of the local filesystem. Supply instances of SecretParams to
|
|
144
|
+
* the secrets array while defining a Function to make their values accessible
|
|
145
|
+
* during execution of that Function.
|
|
146
|
+
*/
|
|
147
|
+
export declare class SecretParam {
|
|
148
|
+
static type: ParamValueType;
|
|
149
|
+
name: string;
|
|
150
|
+
constructor(name: string);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A parametrized value of String type that will be read from .env files
|
|
154
|
+
* if present, or prompted for by the CLI if missing.
|
|
155
|
+
*/
|
|
156
|
+
export declare class StringParam extends Param<string> {
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A parametrized value of Integer type that will be read from .env files
|
|
160
|
+
* if present, or prompted for by the CLI if missing.
|
|
161
|
+
*/
|
|
162
|
+
export declare class IntParam extends Param<number> {
|
|
163
|
+
static type: ParamValueType;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A parametrized value of Float type that will be read from .env files
|
|
167
|
+
* if present, or prompted for by the CLI if missing.
|
|
168
|
+
*/
|
|
169
|
+
export declare class FloatParam extends Param<number> {
|
|
170
|
+
static type: ParamValueType;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* A parametrized value of Boolean type that will be read from .env files
|
|
174
|
+
* if present, or prompted for by the CLI if missing.
|
|
175
|
+
*/
|
|
176
|
+
export declare class BooleanParam extends Param<boolean> {
|
|
177
|
+
static type: ParamValueType;
|
|
178
|
+
then<T extends string | number | boolean>(ifTrue: T | Expression<T>, ifFalse: T | Expression<T>): TernaryExpression<T>;
|
|
179
|
+
}
|
|
180
|
+
export {};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2021 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.BooleanParam = exports.FloatParam = exports.IntParam = exports.InternalExpression = exports.StringParam = exports.SecretParam = exports.Param = exports.CompareExpression = exports.TernaryExpression = exports.Expression = void 0;
|
|
25
|
+
const logger = require("../logger");
|
|
26
|
+
/*
|
|
27
|
+
* A CEL expression which can be evaluated during function deployment, and
|
|
28
|
+
* resolved to a value of the generic type parameter: i.e, you can pass
|
|
29
|
+
* an Expression<number> as the value of an option that normally accepts numbers.
|
|
30
|
+
*/
|
|
31
|
+
class Expression {
|
|
32
|
+
/** Returns the Expression's runtime value, based on the CLI's resolution of params. */
|
|
33
|
+
value() {
|
|
34
|
+
if (process.env.FUNCTIONS_CONTROL_API === "true") {
|
|
35
|
+
logger.warn(`${this.toString()}.value() invoked during function deployment, instead of during runtime.`);
|
|
36
|
+
logger.warn(`This is usually a mistake. In configs, use Params directly without calling .value().`);
|
|
37
|
+
logger.warn(`example: { memory: memoryParam } not { memory: memoryParam.value() }`);
|
|
38
|
+
}
|
|
39
|
+
return this.runtimeValue();
|
|
40
|
+
}
|
|
41
|
+
/** @internal */
|
|
42
|
+
runtimeValue() {
|
|
43
|
+
throw new Error("Not implemented");
|
|
44
|
+
}
|
|
45
|
+
/** Returns the Expression's representation as a braced CEL expression. */
|
|
46
|
+
toCEL() {
|
|
47
|
+
return `{{ ${this.toString()} }}`;
|
|
48
|
+
}
|
|
49
|
+
toJSON() {
|
|
50
|
+
return this.toString();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.Expression = Expression;
|
|
54
|
+
function quoteIfString(literal) {
|
|
55
|
+
// TODO(vsfan@): CEL's string escape semantics are slightly different than Javascript's, what do we do here?
|
|
56
|
+
return typeof literal === "string" ? `"${literal}"` : literal;
|
|
57
|
+
}
|
|
58
|
+
function valueOf(arg) {
|
|
59
|
+
return arg instanceof Expression ? arg.runtimeValue() : arg;
|
|
60
|
+
}
|
|
61
|
+
function refOf(arg) {
|
|
62
|
+
return arg instanceof Expression ? arg.toString() : quoteIfString(arg).toString();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A CEL expression corresponding to a ternary operator, e.g {{ cond ? ifTrue : ifFalse }}
|
|
66
|
+
*/
|
|
67
|
+
class TernaryExpression extends Expression {
|
|
68
|
+
constructor(test, ifTrue, ifFalse) {
|
|
69
|
+
super();
|
|
70
|
+
this.test = test;
|
|
71
|
+
this.ifTrue = ifTrue;
|
|
72
|
+
this.ifFalse = ifFalse;
|
|
73
|
+
this.ifTrue = ifTrue;
|
|
74
|
+
this.ifFalse = ifFalse;
|
|
75
|
+
}
|
|
76
|
+
/** @internal */
|
|
77
|
+
runtimeValue() {
|
|
78
|
+
return this.test.runtimeValue() ? valueOf(this.ifTrue) : valueOf(this.ifFalse);
|
|
79
|
+
}
|
|
80
|
+
toString() {
|
|
81
|
+
return `${this.test} ? ${refOf(this.ifTrue)} : ${refOf(this.ifFalse)}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.TernaryExpression = TernaryExpression;
|
|
85
|
+
/**
|
|
86
|
+
* A CEL expression that evaluates to boolean true or false based on a comparison
|
|
87
|
+
* between the value of another expression and a literal of that same type.
|
|
88
|
+
*/
|
|
89
|
+
class CompareExpression extends Expression {
|
|
90
|
+
constructor(cmp, lhs, rhs) {
|
|
91
|
+
super();
|
|
92
|
+
this.cmp = cmp;
|
|
93
|
+
this.lhs = lhs;
|
|
94
|
+
this.rhs = rhs;
|
|
95
|
+
}
|
|
96
|
+
/** @internal */
|
|
97
|
+
runtimeValue() {
|
|
98
|
+
const left = this.lhs.runtimeValue();
|
|
99
|
+
const right = valueOf(this.rhs);
|
|
100
|
+
switch (this.cmp) {
|
|
101
|
+
case "==":
|
|
102
|
+
return left === right;
|
|
103
|
+
case "!=":
|
|
104
|
+
return left !== right;
|
|
105
|
+
case ">":
|
|
106
|
+
return left > right;
|
|
107
|
+
case ">=":
|
|
108
|
+
return left >= right;
|
|
109
|
+
case "<":
|
|
110
|
+
return left < right;
|
|
111
|
+
case "<=":
|
|
112
|
+
return left <= right;
|
|
113
|
+
default:
|
|
114
|
+
throw new Error(`Unknown comparator ${this.cmp}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
toString() {
|
|
118
|
+
const rhsStr = refOf(this.rhs);
|
|
119
|
+
return `${this.lhs} ${this.cmp} ${rhsStr}`;
|
|
120
|
+
}
|
|
121
|
+
/** Returns a TernaryExpression which can resolve to one of two values, based on the resolution of this comparison. */
|
|
122
|
+
then(ifTrue, ifFalse) {
|
|
123
|
+
return new TernaryExpression(this, ifTrue, ifFalse);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.CompareExpression = CompareExpression;
|
|
127
|
+
/**
|
|
128
|
+
* Represents a parametrized value that will be read from .env files if present,
|
|
129
|
+
* or prompted for by the CLI if missing. Instantiate these with the defineX
|
|
130
|
+
* methods exported by the firebase-functions/params namespace.
|
|
131
|
+
*/
|
|
132
|
+
class Param extends Expression {
|
|
133
|
+
constructor(name, options = {}) {
|
|
134
|
+
super();
|
|
135
|
+
this.name = name;
|
|
136
|
+
this.options = options;
|
|
137
|
+
}
|
|
138
|
+
/** @internal */
|
|
139
|
+
runtimeValue() {
|
|
140
|
+
throw new Error("Not implemented");
|
|
141
|
+
}
|
|
142
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
143
|
+
cmp(cmp, rhs) {
|
|
144
|
+
return new CompareExpression(cmp, this, rhs);
|
|
145
|
+
}
|
|
146
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
147
|
+
equals(rhs) {
|
|
148
|
+
return this.cmp("==", rhs);
|
|
149
|
+
}
|
|
150
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
151
|
+
notEquals(rhs) {
|
|
152
|
+
return this.cmp("!=", rhs);
|
|
153
|
+
}
|
|
154
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
155
|
+
greaterThan(rhs) {
|
|
156
|
+
return this.cmp(">", rhs);
|
|
157
|
+
}
|
|
158
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
159
|
+
greaterThanOrEqualTo(rhs) {
|
|
160
|
+
return this.cmp(">=", rhs);
|
|
161
|
+
}
|
|
162
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
163
|
+
lessThan(rhs) {
|
|
164
|
+
return this.cmp("<", rhs);
|
|
165
|
+
}
|
|
166
|
+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
|
|
167
|
+
lessThanorEqualTo(rhs) {
|
|
168
|
+
return this.cmp("<=", rhs);
|
|
169
|
+
}
|
|
170
|
+
toString() {
|
|
171
|
+
return `params.${this.name}`;
|
|
172
|
+
}
|
|
173
|
+
/** @internal */
|
|
174
|
+
toSpec() {
|
|
175
|
+
const { default: paramDefault, ...otherOptions } = this.options;
|
|
176
|
+
const out = {
|
|
177
|
+
name: this.name,
|
|
178
|
+
...otherOptions,
|
|
179
|
+
type: this.constructor.type,
|
|
180
|
+
};
|
|
181
|
+
if (paramDefault instanceof Expression) {
|
|
182
|
+
out.default = paramDefault.toCEL();
|
|
183
|
+
}
|
|
184
|
+
else if (paramDefault !== undefined) {
|
|
185
|
+
out.default = paramDefault;
|
|
186
|
+
}
|
|
187
|
+
if (out.input && "text" in out.input && out.input.text.validationRegex instanceof RegExp) {
|
|
188
|
+
out.input.text.validationRegex = out.input.text.validationRegex.source;
|
|
189
|
+
}
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.Param = Param;
|
|
194
|
+
Param.type = "string";
|
|
195
|
+
/**
|
|
196
|
+
* A parametrized string whose value is stored in Cloud Secret Manager
|
|
197
|
+
* instead of the local filesystem. Supply instances of SecretParams to
|
|
198
|
+
* the secrets array while defining a Function to make their values accessible
|
|
199
|
+
* during execution of that Function.
|
|
200
|
+
*/
|
|
201
|
+
class SecretParam {
|
|
202
|
+
constructor(name) {
|
|
203
|
+
this.name = name;
|
|
204
|
+
}
|
|
205
|
+
/** @internal */
|
|
206
|
+
runtimeValue() {
|
|
207
|
+
return process.env[this.name] || "";
|
|
208
|
+
}
|
|
209
|
+
/** @internal */
|
|
210
|
+
toSpec() {
|
|
211
|
+
return {
|
|
212
|
+
type: "secret",
|
|
213
|
+
name: this.name,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.SecretParam = SecretParam;
|
|
218
|
+
SecretParam.type = "secret";
|
|
219
|
+
/**
|
|
220
|
+
* A parametrized value of String type that will be read from .env files
|
|
221
|
+
* if present, or prompted for by the CLI if missing.
|
|
222
|
+
*/
|
|
223
|
+
class StringParam extends Param {
|
|
224
|
+
/** @internal */
|
|
225
|
+
runtimeValue() {
|
|
226
|
+
return process.env[this.name] || "";
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.StringParam = StringParam;
|
|
230
|
+
/**
|
|
231
|
+
* A CEL expression which represents an internal Firebase variable. This class
|
|
232
|
+
* cannot be instantiated by developers, but we provide several canned instances
|
|
233
|
+
* of it to make available params that will never have to be defined at
|
|
234
|
+
* deployment time, and can always be read from process.env.
|
|
235
|
+
* @internal
|
|
236
|
+
*/
|
|
237
|
+
class InternalExpression extends Param {
|
|
238
|
+
constructor(name, getter) {
|
|
239
|
+
super(name);
|
|
240
|
+
this.getter = getter;
|
|
241
|
+
}
|
|
242
|
+
/** @internal */
|
|
243
|
+
runtimeValue() {
|
|
244
|
+
return this.getter(process.env) || "";
|
|
245
|
+
}
|
|
246
|
+
toSpec() {
|
|
247
|
+
throw new Error("An InternalExpression should never be marshalled for wire transmission.");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.InternalExpression = InternalExpression;
|
|
251
|
+
/**
|
|
252
|
+
* A parametrized value of Integer type that will be read from .env files
|
|
253
|
+
* if present, or prompted for by the CLI if missing.
|
|
254
|
+
*/
|
|
255
|
+
class IntParam extends Param {
|
|
256
|
+
/** @internal */
|
|
257
|
+
runtimeValue() {
|
|
258
|
+
return parseInt(process.env[this.name] || "0", 10) || 0;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.IntParam = IntParam;
|
|
262
|
+
IntParam.type = "int";
|
|
263
|
+
/**
|
|
264
|
+
* A parametrized value of Float type that will be read from .env files
|
|
265
|
+
* if present, or prompted for by the CLI if missing.
|
|
266
|
+
*/
|
|
267
|
+
class FloatParam extends Param {
|
|
268
|
+
/** @internal */
|
|
269
|
+
runtimeValue() {
|
|
270
|
+
return parseFloat(process.env[this.name] || "0") || 0;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
exports.FloatParam = FloatParam;
|
|
274
|
+
FloatParam.type = "float";
|
|
275
|
+
/**
|
|
276
|
+
* A parametrized value of Boolean type that will be read from .env files
|
|
277
|
+
* if present, or prompted for by the CLI if missing.
|
|
278
|
+
*/
|
|
279
|
+
class BooleanParam extends Param {
|
|
280
|
+
/** @internal */
|
|
281
|
+
runtimeValue() {
|
|
282
|
+
return !!process.env[this.name] && process.env[this.name] === "true";
|
|
283
|
+
}
|
|
284
|
+
then(ifTrue, ifFalse) {
|
|
285
|
+
return new TernaryExpression(this, ifTrue, ifFalse);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
exports.BooleanParam = BooleanParam;
|
|
289
|
+
BooleanParam.type = "boolean";
|
package/lib/runtime/loader.js
CHANGED
|
@@ -24,26 +24,26 @@ exports.loadStack = exports.mergeRequiredAPIs = exports.extractStack = void 0;
|
|
|
24
24
|
// SOFTWARE.
|
|
25
25
|
const path = require("path");
|
|
26
26
|
const url = require("url");
|
|
27
|
-
const params = require("../
|
|
27
|
+
const params = require("../params");
|
|
28
28
|
/**
|
|
29
29
|
* Dynamically load import function to prevent TypeScript from
|
|
30
30
|
* transpiling into a require.
|
|
31
31
|
*
|
|
32
32
|
* See https://github.com/microsoft/TypeScript/issues/43329.
|
|
33
|
+
*
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
36
|
+
const dynamicImport = new Function("modulePath", "return import(modulePath)");
|
|
35
37
|
async function loadModule(functionsDir) {
|
|
36
38
|
const absolutePath = path.resolve(functionsDir);
|
|
37
39
|
try {
|
|
38
40
|
return require(path.resolve(absolutePath));
|
|
39
41
|
}
|
|
40
42
|
catch (e) {
|
|
41
|
-
if (e.code ===
|
|
43
|
+
if (e.code === "ERR_REQUIRE_ESM") {
|
|
42
44
|
// This is an ESM package!
|
|
43
45
|
const modulePath = require.resolve(absolutePath);
|
|
44
46
|
// Resolve module path to file:// URL. Required for windows support.
|
|
45
|
-
// @ts-ignore pathToFileURL exists for Node.js v10 and up. Since ESM support exists for Node.js v13 and up, we
|
|
46
|
-
// can be sure that this function exists here.
|
|
47
47
|
const moduleURL = url.pathToFileURL(modulePath).href;
|
|
48
48
|
return await dynamicImport(moduleURL);
|
|
49
49
|
}
|
|
@@ -51,24 +51,22 @@ async function loadModule(functionsDir) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
/* @internal */
|
|
54
|
-
function extractStack(module, endpoints, requiredAPIs, prefix =
|
|
54
|
+
function extractStack(module, endpoints, requiredAPIs, prefix = "") {
|
|
55
55
|
for (const [name, valAsUnknown] of Object.entries(module)) {
|
|
56
56
|
// We're introspecting untrusted code here. Any is appropraite
|
|
57
57
|
const val = valAsUnknown;
|
|
58
|
-
if (typeof val ===
|
|
59
|
-
val.__endpoint &&
|
|
60
|
-
typeof val.__endpoint === 'object') {
|
|
58
|
+
if (typeof val === "function" && val.__endpoint && typeof val.__endpoint === "object") {
|
|
61
59
|
const funcName = prefix + name;
|
|
62
60
|
endpoints[funcName] = {
|
|
63
61
|
...val.__endpoint,
|
|
64
|
-
entryPoint: funcName.replace(/-/g,
|
|
62
|
+
entryPoint: funcName.replace(/-/g, "."),
|
|
65
63
|
};
|
|
66
64
|
if (val.__requiredAPIs && Array.isArray(val.__requiredAPIs)) {
|
|
67
65
|
requiredAPIs.push(...val.__requiredAPIs);
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
|
-
else if (typeof val ===
|
|
71
|
-
extractStack(val, endpoints, requiredAPIs, prefix + name +
|
|
68
|
+
else if (typeof val === "object" && val !== null) {
|
|
69
|
+
extractStack(val, endpoints, requiredAPIs, prefix + name + "-");
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
}
|
|
@@ -83,7 +81,7 @@ function mergeRequiredAPIs(requiredAPIs) {
|
|
|
83
81
|
}
|
|
84
82
|
const merged = [];
|
|
85
83
|
for (const [api, reasons] of Object.entries(apiToReasons)) {
|
|
86
|
-
merged.push({ api, reason: Array.from(reasons).join(
|
|
84
|
+
merged.push({ api, reason: Array.from(reasons).join(" ") });
|
|
87
85
|
}
|
|
88
86
|
return merged;
|
|
89
87
|
}
|
|
@@ -96,7 +94,7 @@ async function loadStack(functionsDir) {
|
|
|
96
94
|
extractStack(mod, endpoints, requiredAPIs);
|
|
97
95
|
const stack = {
|
|
98
96
|
endpoints,
|
|
99
|
-
specVersion:
|
|
97
|
+
specVersion: "v1alpha1",
|
|
100
98
|
requiredAPIs: mergeRequiredAPIs(requiredAPIs),
|
|
101
99
|
};
|
|
102
100
|
if (params.declaredParams.length > 0) {
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ResetValue } from "../common/options";
|
|
2
|
+
import { Expression } from "../params";
|
|
3
|
+
import { WireParamSpec } from "../params/types";
|
|
3
4
|
/**
|
|
4
5
|
* An definition of a function as appears in the Manifest.
|
|
6
|
+
*
|
|
7
|
+
* @alpha
|
|
5
8
|
*/
|
|
6
9
|
export interface ManifestEndpoint {
|
|
7
10
|
entryPoint?: string;
|
|
8
11
|
region?: string[];
|
|
9
12
|
platform?: string;
|
|
10
|
-
availableMemoryMb?: number | Expression<number
|
|
11
|
-
maxInstances?: number | Expression<number
|
|
12
|
-
minInstances?: number | Expression<number
|
|
13
|
-
concurrency?: number | Expression<number
|
|
14
|
-
|
|
15
|
-
timeoutSeconds?: number | Expression<number>;
|
|
16
|
-
cpu?: number | 'gcf_gen1';
|
|
13
|
+
availableMemoryMb?: number | Expression<number> | ResetValue;
|
|
14
|
+
maxInstances?: number | Expression<number> | ResetValue;
|
|
15
|
+
minInstances?: number | Expression<number> | ResetValue;
|
|
16
|
+
concurrency?: number | Expression<number> | ResetValue;
|
|
17
|
+
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
17
18
|
vpc?: {
|
|
18
19
|
connector: string | Expression<string>;
|
|
19
|
-
egressSettings?: string;
|
|
20
|
-
};
|
|
20
|
+
egressSettings?: string | Expression<string> | ResetValue;
|
|
21
|
+
} | ResetValue;
|
|
22
|
+
serviceAccountEmail?: string | Expression<string> | ResetValue;
|
|
23
|
+
cpu?: number | "gcf_gen1";
|
|
21
24
|
labels?: Record<string, string>;
|
|
22
|
-
ingressSettings?: string;
|
|
25
|
+
ingressSettings?: string | Expression<string> | ResetValue;
|
|
23
26
|
environmentVariables?: Record<string, string>;
|
|
24
27
|
secretEnvironmentVariables?: Array<{
|
|
25
28
|
key: string;
|
|
@@ -28,25 +31,41 @@ export interface ManifestEndpoint {
|
|
|
28
31
|
httpsTrigger?: {
|
|
29
32
|
invoker?: string[];
|
|
30
33
|
};
|
|
31
|
-
callableTrigger?:
|
|
34
|
+
callableTrigger?: Record<string, never>;
|
|
32
35
|
eventTrigger?: {
|
|
33
36
|
eventFilters: Record<string, string | Expression<string>>;
|
|
34
37
|
eventFilterPathPatterns?: Record<string, string | Expression<string>>;
|
|
35
38
|
channel?: string;
|
|
36
39
|
eventType: string;
|
|
37
|
-
retry: boolean | Expression<boolean
|
|
40
|
+
retry: boolean | Expression<boolean> | ResetValue;
|
|
38
41
|
region?: string;
|
|
39
|
-
serviceAccountEmail?: string;
|
|
42
|
+
serviceAccountEmail?: string | ResetValue;
|
|
43
|
+
};
|
|
44
|
+
taskQueueTrigger?: {
|
|
45
|
+
retryConfig?: {
|
|
46
|
+
maxAttempts?: number | Expression<number> | ResetValue;
|
|
47
|
+
maxRetrySeconds?: number | Expression<number> | ResetValue;
|
|
48
|
+
maxBackoffSeconds?: number | Expression<number> | ResetValue;
|
|
49
|
+
maxDoublings?: number | Expression<number> | ResetValue;
|
|
50
|
+
minBackoffSeconds?: number | Expression<number> | ResetValue;
|
|
51
|
+
};
|
|
52
|
+
rateLimits?: {
|
|
53
|
+
maxConcurrentDispatches?: number | Expression<number> | ResetValue;
|
|
54
|
+
maxDispatchesPerSecond?: number | Expression<number> | ResetValue;
|
|
55
|
+
};
|
|
40
56
|
};
|
|
41
57
|
scheduleTrigger?: {
|
|
42
|
-
schedule
|
|
43
|
-
timeZone?: string | Expression<string
|
|
58
|
+
schedule: string | Expression<string>;
|
|
59
|
+
timeZone?: string | Expression<string> | ResetValue;
|
|
44
60
|
retryConfig?: {
|
|
45
|
-
retryCount?: number | Expression<number
|
|
46
|
-
maxRetrySeconds?: string | Expression<string
|
|
47
|
-
minBackoffSeconds?: string | Expression<string
|
|
48
|
-
maxBackoffSeconds?: string | Expression<string
|
|
49
|
-
maxDoublings?: number | Expression<number
|
|
61
|
+
retryCount?: number | Expression<number> | ResetValue;
|
|
62
|
+
maxRetrySeconds?: string | Expression<string> | ResetValue;
|
|
63
|
+
minBackoffSeconds?: string | Expression<string> | ResetValue;
|
|
64
|
+
maxBackoffSeconds?: string | Expression<string> | ResetValue;
|
|
65
|
+
maxDoublings?: number | Expression<number> | ResetValue;
|
|
66
|
+
maxRetryDuration?: string | Expression<string> | ResetValue;
|
|
67
|
+
minBackoffDuration?: string | Expression<string> | ResetValue;
|
|
68
|
+
maxBackoffDuration?: string | Expression<string> | ResetValue;
|
|
50
69
|
};
|
|
51
70
|
};
|
|
52
71
|
blockingTrigger?: {
|
|
@@ -54,16 +73,29 @@ export interface ManifestEndpoint {
|
|
|
54
73
|
options?: Record<string, unknown>;
|
|
55
74
|
};
|
|
56
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Description of API required for this stack.
|
|
78
|
+
* @alpha
|
|
79
|
+
*/
|
|
57
80
|
export interface ManifestRequiredAPI {
|
|
58
81
|
api: string;
|
|
59
82
|
reason: string;
|
|
60
83
|
}
|
|
61
84
|
/**
|
|
62
85
|
* An definition of a function deployment as appears in the Manifest.
|
|
86
|
+
* @alpha
|
|
63
87
|
*/
|
|
64
88
|
export interface ManifestStack {
|
|
65
|
-
specVersion:
|
|
66
|
-
params?:
|
|
89
|
+
specVersion: "v1alpha1";
|
|
90
|
+
params?: WireParamSpec<any>[];
|
|
67
91
|
requiredAPIs: ManifestRequiredAPI[];
|
|
68
92
|
endpoints: Record<string, ManifestEndpoint>;
|
|
69
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns the JSON representation of a ManifestStack, which has CEL
|
|
96
|
+
* expressions in its options as object types, with its expressions
|
|
97
|
+
* transformed into the actual CEL strings.
|
|
98
|
+
*
|
|
99
|
+
* @alpha
|
|
100
|
+
*/
|
|
101
|
+
export declare function stackToWire(stack: ManifestStack): Record<string, unknown>;
|