This commit is contained in:
girinb
2025-05-29 15:41:51 +09:00
parent a1bd4f87a1
commit 485098cd1a
5611 changed files with 881685 additions and 0 deletions

71
node_modules/firebase-functions/lib/params/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,71 @@
/**
* @hidden
* @alpha
*/
import { BooleanParam, Expression, IntParam, Param, ParamOptions, SecretParam, StringParam, ListParam } from "./types";
export { BUCKET_PICKER, TextInput, SelectInput, SelectOptions, MultiSelectInput, select, multiSelect, } from "./types";
export { ParamOptions, Expression };
type SecretOrExpr = Param<any> | SecretParam;
export declare const declaredParams: SecretOrExpr[];
/**
* A built-in parameter that resolves to the default RTDB database URL associated
* with the project, without prompting the deployer. Empty string if none exists.
*/
export declare const databaseURL: Param<string>;
/**
* A built-in parameter that resolves to the Cloud project ID associated with
* the project, without prompting the deployer.
*/
export declare const projectID: Param<string>;
/**
* A built-in parameter that resolves to the Cloud project ID, without prompting
* the deployer.
*/
export declare const gcloudProject: Param<string>;
/**
* A builtin parameter that resolves to the Cloud storage bucket associated
* with the function, without prompting the deployer. Empty string if not
* defined.
*/
export declare const storageBucket: Param<string>;
/**
* Declares a secret param, that will persist values only in Cloud Secret Manager.
* Secrets are stored internally as bytestrings. Use `ParamOptions.as` to provide type
* hinting during parameter resolution.
*
* @param name The name of the environment variable to use to load the parameter.
* @returns A parameter with a `string` return type for `.value`.
*/
export declare function defineSecret(name: string): SecretParam;
/**
* Declare a string parameter.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `string` return type for `.value`.
*/
export declare function defineString(name: string, options?: ParamOptions<string>): StringParam;
/**
* Declare a boolean parameter.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `boolean` return type for `.value`.
*/
export declare function defineBoolean(name: string, options?: ParamOptions<boolean>): BooleanParam;
/**
* Declare an integer parameter.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `number` return type for `.value`.
*/
export declare function defineInt(name: string, options?: ParamOptions<number>): IntParam;
/**
* Declare a list parameter.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `string[]` return type for `.value`.
*/
export declare function defineList(name: string, options?: ParamOptions<string[]>): ListParam;

158
node_modules/firebase-functions/lib/params/index.js generated vendored Normal file
View File

@@ -0,0 +1,158 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2021 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineList = exports.defineFloat = exports.defineInt = exports.defineBoolean = exports.defineString = exports.defineSecret = exports.storageBucket = exports.gcloudProject = exports.projectID = exports.databaseURL = exports.clearParams = exports.declaredParams = exports.Expression = exports.multiSelect = exports.select = exports.BUCKET_PICKER = void 0;
/**
* @hidden
* @alpha
*/
const types_1 = require("./types");
Object.defineProperty(exports, "Expression", { enumerable: true, get: function () { return types_1.Expression; } });
var types_2 = require("./types");
Object.defineProperty(exports, "BUCKET_PICKER", { enumerable: true, get: function () { return types_2.BUCKET_PICKER; } });
Object.defineProperty(exports, "select", { enumerable: true, get: function () { return types_2.select; } });
Object.defineProperty(exports, "multiSelect", { enumerable: true, get: function () { return types_2.multiSelect; } });
exports.declaredParams = [];
/**
* Use a helper to manage the list such that parameters are uniquely
* registered once only but order is preserved.
* @internal
*/
function registerParam(param) {
for (let i = 0; i < exports.declaredParams.length; i++) {
if (exports.declaredParams[i].name === param.name) {
exports.declaredParams.splice(i, 1);
}
}
exports.declaredParams.push(param);
}
/**
* For testing.
* @internal
*/
function clearParams() {
exports.declaredParams.splice(0, exports.declaredParams.length);
}
exports.clearParams = clearParams;
/**
* A built-in parameter that resolves to the default RTDB database URL associated
* with the project, without prompting the deployer. Empty string if none exists.
*/
exports.databaseURL = new types_1.InternalExpression("DATABASE_URL", (env) => { var _a; return ((_a = JSON.parse(env.FIREBASE_CONFIG)) === null || _a === void 0 ? void 0 : _a.databaseURL) || ""; });
/**
* A built-in parameter that resolves to the Cloud project ID associated with
* the project, without prompting the deployer.
*/
exports.projectID = new types_1.InternalExpression("PROJECT_ID", (env) => { var _a; return ((_a = JSON.parse(env.FIREBASE_CONFIG)) === null || _a === void 0 ? void 0 : _a.projectId) || ""; });
/**
* A built-in parameter that resolves to the Cloud project ID, without prompting
* the deployer.
*/
exports.gcloudProject = new types_1.InternalExpression("GCLOUD_PROJECT", (env) => { var _a; return ((_a = JSON.parse(env.FIREBASE_CONFIG)) === null || _a === void 0 ? void 0 : _a.projectId) || ""; });
/**
* A builtin parameter that resolves to the Cloud storage bucket associated
* with the function, without prompting the deployer. Empty string if not
* defined.
*/
exports.storageBucket = new types_1.InternalExpression("STORAGE_BUCKET", (env) => { var _a; return ((_a = JSON.parse(env.FIREBASE_CONFIG)) === null || _a === void 0 ? void 0 : _a.storageBucket) || ""; });
/**
* Declares a secret param, that will persist values only in Cloud Secret Manager.
* Secrets are stored internally as bytestrings. Use `ParamOptions.as` to provide type
* hinting during parameter resolution.
*
* @param name The name of the environment variable to use to load the parameter.
* @returns A parameter with a `string` return type for `.value`.
*/
function defineSecret(name) {
const param = new types_1.SecretParam(name);
registerParam(param);
return param;
}
exports.defineSecret = defineSecret;
/**
* Declare a string parameter.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `string` return type for `.value`.
*/
function defineString(name, options = {}) {
const param = new types_1.StringParam(name, options);
registerParam(param);
return param;
}
exports.defineString = defineString;
/**
* Declare a boolean parameter.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `boolean` return type for `.value`.
*/
function defineBoolean(name, options = {}) {
const param = new types_1.BooleanParam(name, options);
registerParam(param);
return param;
}
exports.defineBoolean = defineBoolean;
/**
* Declare an integer parameter.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `number` return type for `.value`.
*/
function defineInt(name, options = {}) {
const param = new types_1.IntParam(name, options);
registerParam(param);
return param;
}
exports.defineInt = defineInt;
/**
* Declare a float parameter.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `number` return type for `.value`.
*
* @internal
*/
function defineFloat(name, options = {}) {
const param = new types_1.FloatParam(name, options);
registerParam(param);
return param;
}
exports.defineFloat = defineFloat;
/**
* Declare a list parameter.
*
* @param name The name of the environment variable to use to load the parameter.
* @param options Configuration options for the parameter.
* @returns A parameter with a `string[]` return type for `.value`.
*/
function defineList(name, options = {}) {
const param = new types_1.ListParam(name, options);
registerParam(param);
return param;
}
exports.defineList = defineList;

225
node_modules/firebase-functions/lib/params/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,225 @@
export declare abstract class Expression<T extends string | number | boolean | string[]> {
/** Returns the expression's runtime value, based on the CLI's resolution of parameters. */
value(): T;
/** Returns the expression's representation as a braced CEL expression. */
toCEL(): string;
/** Returns the expression's representation as JSON. */
toJSON(): string;
}
/**
* A CEL expression corresponding to a ternary operator, e.g {{ cond ? ifTrue : ifFalse }}
*/
export declare class TernaryExpression<T extends string | number | boolean | string[]> extends Expression<T> {
private readonly test;
private readonly ifTrue;
private readonly ifFalse;
constructor(test: Expression<boolean>, ifTrue: T | Expression<T>, ifFalse: T | Expression<T>);
toString(): string;
}
/**
* A CEL expression that evaluates to boolean true or false based on a comparison
* between the value of another expression and a literal of that same type.
*/
export declare class CompareExpression<T extends string | number | boolean | string[]> extends Expression<boolean> {
cmp: "==" | "!=" | ">" | ">=" | "<" | "<=";
lhs: Expression<T>;
rhs: T | Expression<T>;
constructor(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", lhs: Expression<T>, rhs: T | Expression<T>);
toString(): string;
/** Returns a `TernaryExpression` which can resolve to one of two values, based on the resolution of this comparison. */
thenElse<retT extends string | number | boolean | string[]>(ifTrue: retT | Expression<retT>, ifFalse: retT | Expression<retT>): TernaryExpression<retT>;
}
/** @hidden */
type ParamValueType = "string" | "list" | "boolean" | "int" | "float" | "secret";
/** Create a select input from a series of values. */
export declare function select<T>(options: T[]): SelectInput<T>;
/** Create a select input from a map of labels to values. */
export declare function select<T>(optionsWithLabels: Record<string, T>): SelectInput<T>;
/** Create a multi-select input from a series of values. */
export declare function multiSelect(options: string[]): MultiSelectInput;
/** Create a multi-select input from map of labels to values. */
export declare function multiSelect(options: Record<string, string>): MultiSelectInput;
type ParamInput<T> = TextInput<T> | SelectInput<T> | (T extends string[] ? MultiSelectInput : never) | (T extends string ? ResourceInput : never);
/**
* Specifies that a parameter's value should be determined by prompting the user
* to type it in interactively at deploy time. Input that does not match the
* provided validationRegex, if present, will be retried.
*/
export interface TextInput<T = unknown> {
text: {
example?: string;
/**
* A regular expression (or an escaped string to compile into a regular
* expression) which the prompted text must satisfy; the prompt will retry
* until input matching the regex is provided.
*/
validationRegex?: string | RegExp;
/**
* A custom error message to display when retrying the prompt based on input
* failing to conform to the validationRegex,
*/
validationErrorMessage?: string;
};
}
/**
* Specifies that a parameter's value should be determined by having the user
* select from a list containing all the project's resources of a certain
* type. Currently, only type:"storage.googleapis.com/Bucket" is supported.
*/
export interface ResourceInput {
resource: {
type: "storage.googleapis.com/Bucket";
};
}
/**
* Autogenerate a list of buckets in a project that a user can select from.
*/
export declare const BUCKET_PICKER: ResourceInput;
/**
* Specifies that a parameter's value should be determined by having the user select
* from a list of pre-canned options interactively at deploy time.
*/
export interface SelectInput<T = unknown> {
select: {
options: Array<SelectOptions<T>>;
};
}
/**
* Specifies that a parameter's value should be determined by having the user select
* a subset from a list of pre-canned options interactively at deploy time.
* Will result in errors if used on parameters of type other than `string[]`.
*/
export interface MultiSelectInput {
multiSelect: {
options: Array<SelectOptions<string>>;
};
}
/**
* One of the options provided to a `SelectInput`, containing a value and
* optionally a human-readable label to display in the selection interface.
*/
export interface SelectOptions<T = unknown> {
label?: string;
value: T;
}
/** The wire representation of a parameter when it's sent to the CLI. A superset of `ParamOptions`. */
export type ParamSpec<T extends string | number | boolean | string[]> = {
/** The name of the parameter which will be stored in .env files. Use UPPERCASE. */
name: string;
/** An optional default value to be used while prompting for input. Can be a literal or another parametrized expression. */
default?: T | Expression<T>;
/** An optional human-readable string to be used as a replacement for the parameter's name when prompting. */
label?: string;
/** An optional long-form description of the parameter to be displayed while prompting. */
description?: string;
/** The way in which the Firebase CLI will prompt for the value of this parameter. Defaults to a TextInput. */
input?: ParamInput<T>;
};
/**
* Representation of parameters for the stack over the wire.
*
* @remarks
* N.B: a WireParamSpec is just a ParamSpec with default expressions converted into a CEL literal
*
* @alpha
*/
export type WireParamSpec<T extends string | number | boolean | string[]> = {
name: string;
default?: T | string;
label?: string;
description?: string;
type: ParamValueType;
input?: ParamInput<T>;
};
/** Configuration options which can be used to customize the prompting behavior of a parameter. */
export type ParamOptions<T extends string | number | boolean | string[]> = Omit<ParamSpec<T>, "name" | "type">;
/**
* Represents a parametrized value that will be read from .env files if present,
* or prompted for by the CLI if missing. Instantiate these with the defineX
* methods exported by the firebase-functions/params namespace.
*/
export declare abstract class Param<T extends string | number | boolean | string[]> extends Expression<T> {
readonly name: string;
readonly options: ParamOptions<T>;
static type: ParamValueType;
constructor(name: string, options?: ParamOptions<T>);
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
cmp(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", rhs: T | Expression<T>): CompareExpression<T>;
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
equals(rhs: T | Expression<T>): CompareExpression<T>;
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
notEquals(rhs: T | Expression<T>): CompareExpression<T>;
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
greaterThan(rhs: T | Expression<T>): CompareExpression<T>;
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
greaterThanOrEqualTo(rhs: T | Expression<T>): CompareExpression<T>;
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
lessThan(rhs: T | Expression<T>): CompareExpression<T>;
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
lessThanOrEqualTo(rhs: T | Expression<T>): CompareExpression<T>;
/**
* Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression.
* @deprecated A typo. Use lessThanOrEqualTo instead.
*/
lessThanorEqualTo(rhs: T | Expression<T>): CompareExpression<T>;
toString(): string;
}
/**
* A parametrized string whose value is stored in Cloud Secret Manager
* instead of the local filesystem. Supply instances of SecretParams to
* the secrets array while defining a Function to make their values accessible
* during execution of that Function.
*/
export declare class SecretParam {
static type: ParamValueType;
name: string;
constructor(name: string);
/** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
value(): string;
}
/**
* A parametrized value of String type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
export declare class StringParam extends Param<string> {
}
/**
* A parametrized value of Integer type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
export declare class IntParam extends Param<number> {
static type: ParamValueType;
}
/**
* A parametrized value of Float type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
export declare class FloatParam extends Param<number> {
static type: ParamValueType;
}
/**
* A parametrized value of Boolean type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
export declare class BooleanParam extends Param<boolean> {
static type: ParamValueType;
/** @deprecated */
then<T extends string | number | boolean>(ifTrue: T | Expression<T>, ifFalse: T | Expression<T>): TernaryExpression<T>;
thenElse<T extends string | number | boolean>(ifTrue: T | Expression<T>, ifFalse: T | Expression<T>): TernaryExpression<T>;
}
/**
* A parametrized value of String[] type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
export declare class ListParam extends Param<string[]> {
static type: ParamValueType;
/** @hidden */
greaterThan(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
/** @hidden */
greaterThanOrEqualTo(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
/** @hidden */
lessThan(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
/** @hidden */
lessThanorEqualTo(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
}
export {};

406
node_modules/firebase-functions/lib/params/types.js generated vendored Normal file
View File

@@ -0,0 +1,406 @@
"use strict";
// The MIT License (MIT)
//
// Copyright (c) 2021 Firebase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListParam = exports.BooleanParam = exports.FloatParam = exports.IntParam = exports.InternalExpression = exports.StringParam = exports.SecretParam = exports.Param = exports.BUCKET_PICKER = exports.multiSelect = exports.select = exports.CompareExpression = exports.TernaryExpression = exports.Expression = void 0;
const logger = require("../logger");
/*
* A CEL expression which can be evaluated during function deployment, and
* resolved to a value of the generic type parameter: i.e, you can pass
* an Expression<number> as the value of an option that normally accepts numbers.
*/
class Expression {
/** Returns the expression's runtime value, based on the CLI's resolution of parameters. */
value() {
if (process.env.FUNCTIONS_CONTROL_API === "true") {
logger.warn(`${this.toString()}.value() invoked during function deployment, instead of during runtime.`);
logger.warn(`This is usually a mistake. In configs, use Params directly without calling .value().`);
logger.warn(`example: { memory: memoryParam } not { memory: memoryParam.value() }`);
}
return this.runtimeValue();
}
/** @internal */
runtimeValue() {
throw new Error("Not implemented");
}
/** Returns the expression's representation as a braced CEL expression. */
toCEL() {
return `{{ ${this.toString()} }}`;
}
/** Returns the expression's representation as JSON. */
toJSON() {
return this.toString();
}
}
exports.Expression = Expression;
function valueOf(arg) {
return arg instanceof Expression ? arg.runtimeValue() : arg;
}
/**
* Returns how an entity (either an `Expression` or a literal value) should be represented in CEL.
* - Expressions delegate to the `.toString()` method, which is used by the WireManifest
* - Strings have to be quoted explicitly
* - Arrays are represented as []-delimited, parsable JSON
* - Numbers and booleans are not quoted explicitly
*/
function refOf(arg) {
if (arg instanceof Expression) {
return arg.toString();
}
else if (typeof arg === "string") {
return `"${arg}"`;
}
else if (Array.isArray(arg)) {
return JSON.stringify(arg);
}
else {
return arg.toString();
}
}
/**
* A CEL expression corresponding to a ternary operator, e.g {{ cond ? ifTrue : ifFalse }}
*/
class TernaryExpression extends Expression {
constructor(test, ifTrue, ifFalse) {
super();
this.test = test;
this.ifTrue = ifTrue;
this.ifFalse = ifFalse;
this.ifTrue = ifTrue;
this.ifFalse = ifFalse;
}
/** @internal */
runtimeValue() {
return this.test.runtimeValue() ? valueOf(this.ifTrue) : valueOf(this.ifFalse);
}
toString() {
return `${this.test} ? ${refOf(this.ifTrue)} : ${refOf(this.ifFalse)}`;
}
}
exports.TernaryExpression = TernaryExpression;
/**
* A CEL expression that evaluates to boolean true or false based on a comparison
* between the value of another expression and a literal of that same type.
*/
class CompareExpression extends Expression {
constructor(cmp, lhs, rhs) {
super();
this.cmp = cmp;
this.lhs = lhs;
this.rhs = rhs;
}
/** @internal */
runtimeValue() {
const left = this.lhs.runtimeValue();
const right = valueOf(this.rhs);
switch (this.cmp) {
case "==":
return Array.isArray(left) ? this.arrayEquals(left, right) : left === right;
case "!=":
return Array.isArray(left) ? !this.arrayEquals(left, right) : left !== right;
case ">":
return left > right;
case ">=":
return left >= right;
case "<":
return left < right;
case "<=":
return left <= right;
default:
throw new Error(`Unknown comparator ${this.cmp}`);
}
}
/** @internal */
arrayEquals(a, b) {
return a.every((item) => b.includes(item)) && b.every((item) => a.includes(item));
}
toString() {
const rhsStr = refOf(this.rhs);
return `${this.lhs} ${this.cmp} ${rhsStr}`;
}
/** Returns a `TernaryExpression` which can resolve to one of two values, based on the resolution of this comparison. */
thenElse(ifTrue, ifFalse) {
return new TernaryExpression(this, ifTrue, ifFalse);
}
}
exports.CompareExpression = CompareExpression;
/** Create a select input from a series of values or a map of labels to values */
function select(options) {
let wireOpts;
if (Array.isArray(options)) {
wireOpts = options.map((opt) => ({ value: opt }));
}
else {
wireOpts = Object.entries(options).map(([label, value]) => ({ label, value }));
}
return {
select: {
options: wireOpts,
},
};
}
exports.select = select;
/** Create a multi-select input from a series of values or map of labels to values. */
function multiSelect(options) {
let wireOpts;
if (Array.isArray(options)) {
wireOpts = options.map((opt) => ({ value: opt }));
}
else {
wireOpts = Object.entries(options).map(([label, value]) => ({ label, value }));
}
return {
multiSelect: {
options: wireOpts,
},
};
}
exports.multiSelect = multiSelect;
/**
* Autogenerate a list of buckets in a project that a user can select from.
*/
exports.BUCKET_PICKER = {
resource: {
type: "storage.googleapis.com/Bucket",
},
};
/**
* Represents a parametrized value that will be read from .env files if present,
* or prompted for by the CLI if missing. Instantiate these with the defineX
* methods exported by the firebase-functions/params namespace.
*/
class Param extends Expression {
constructor(name, options = {}) {
super();
this.name = name;
this.options = options;
}
/** @internal */
runtimeValue() {
throw new Error("Not implemented");
}
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
cmp(cmp, rhs) {
return new CompareExpression(cmp, this, rhs);
}
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
equals(rhs) {
return this.cmp("==", rhs);
}
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
notEquals(rhs) {
return this.cmp("!=", rhs);
}
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
greaterThan(rhs) {
return this.cmp(">", rhs);
}
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
greaterThanOrEqualTo(rhs) {
return this.cmp(">=", rhs);
}
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
lessThan(rhs) {
return this.cmp("<", rhs);
}
/** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
lessThanOrEqualTo(rhs) {
return this.cmp("<=", rhs);
}
/**
* Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression.
* @deprecated A typo. Use lessThanOrEqualTo instead.
*/
lessThanorEqualTo(rhs) {
return this.lessThanOrEqualTo(rhs);
}
toString() {
return `params.${this.name}`;
}
/** @internal */
toSpec() {
const { default: paramDefault, ...otherOptions } = this.options;
const out = {
name: this.name,
...otherOptions,
type: this.constructor.type,
};
if (paramDefault instanceof Expression) {
out.default = paramDefault.toCEL();
}
else if (paramDefault !== undefined) {
out.default = paramDefault;
}
if (out.input && "text" in out.input && out.input.text.validationRegex instanceof RegExp) {
out.input.text.validationRegex = out.input.text.validationRegex.source;
}
return out;
}
}
exports.Param = Param;
Param.type = "string";
/**
* A parametrized string whose value is stored in Cloud Secret Manager
* instead of the local filesystem. Supply instances of SecretParams to
* the secrets array while defining a Function to make their values accessible
* during execution of that Function.
*/
class SecretParam {
constructor(name) {
this.name = name;
}
/** @internal */
runtimeValue() {
const val = process.env[this.name];
if (val === undefined) {
logger.warn(`No value found for secret parameter "${this.name}". A function can only access a secret if you include the secret in the function's dependency array.`);
}
return val || "";
}
/** @internal */
toSpec() {
return {
type: "secret",
name: this.name,
};
}
/** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
value() {
if (process.env.FUNCTIONS_CONTROL_API === "true") {
throw new Error(`Cannot access the value of secret "${this.name}" during function deployment. Secret values are only available at runtime.`);
}
return this.runtimeValue();
}
}
exports.SecretParam = SecretParam;
SecretParam.type = "secret";
/**
* A parametrized value of String type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
class StringParam extends Param {
/** @internal */
runtimeValue() {
return process.env[this.name] || "";
}
}
exports.StringParam = StringParam;
/**
* A CEL expression which represents an internal Firebase variable. This class
* cannot be instantiated by developers, but we provide several canned instances
* of it to make available parameters that will never have to be defined at
* deployment time, and can always be read from process.env.
* @internal
*/
class InternalExpression extends Param {
constructor(name, getter) {
super(name);
this.getter = getter;
}
/** @internal */
runtimeValue() {
return this.getter(process.env) || "";
}
toSpec() {
throw new Error("An InternalExpression should never be marshalled for wire transmission.");
}
}
exports.InternalExpression = InternalExpression;
/**
* A parametrized value of Integer type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
class IntParam extends Param {
/** @internal */
runtimeValue() {
return parseInt(process.env[this.name] || "0", 10) || 0;
}
}
exports.IntParam = IntParam;
IntParam.type = "int";
/**
* A parametrized value of Float type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
class FloatParam extends Param {
/** @internal */
runtimeValue() {
return parseFloat(process.env[this.name] || "0") || 0;
}
}
exports.FloatParam = FloatParam;
FloatParam.type = "float";
/**
* A parametrized value of Boolean type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
class BooleanParam extends Param {
/** @internal */
runtimeValue() {
return !!process.env[this.name] && process.env[this.name] === "true";
}
/** @deprecated */
then(ifTrue, ifFalse) {
return this.thenElse(ifTrue, ifFalse);
}
thenElse(ifTrue, ifFalse) {
return new TernaryExpression(this, ifTrue, ifFalse);
}
}
exports.BooleanParam = BooleanParam;
BooleanParam.type = "boolean";
/**
* A parametrized value of String[] type that will be read from .env files
* if present, or prompted for by the CLI if missing.
*/
class ListParam extends Param {
/** @internal */
runtimeValue() {
const val = JSON.parse(process.env[this.name]);
if (!Array.isArray(val) || !val.every((v) => typeof v === "string")) {
return [];
}
return val;
}
/** @hidden */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
greaterThan(rhs) {
throw new Error(">/< comparison operators not supported on params of type List");
}
/** @hidden */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
greaterThanOrEqualTo(rhs) {
throw new Error(">/< comparison operators not supported on params of type List");
}
/** @hidden */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
lessThan(rhs) {
throw new Error(">/< comparison operators not supported on params of type List");
}
/** @hidden */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
lessThanorEqualTo(rhs) {
throw new Error(">/< comparison operators not supported on params of type List");
}
}
exports.ListParam = ListParam;
ListParam.type = "list";