UNPKG

10.7 kBTypeScriptView Raw
1export declare abstract class Expression<T extends string | number | boolean | string[]> {
2 /** Returns the expression's runtime value, based on the CLI's resolution of parameters. */
3 value(): T;
4 /** Returns the expression's representation as a braced CEL expression. */
5 toCEL(): string;
6 /** Returns the expression's representation as JSON. */
7 toJSON(): string;
8}
9/**
10 * A CEL expression corresponding to a ternary operator, e.g {{ cond ? ifTrue : ifFalse }}
11 */
12export declare class TernaryExpression<T extends string | number | boolean | string[]> extends Expression<T> {
13 private readonly test;
14 private readonly ifTrue;
15 private readonly ifFalse;
16 constructor(test: Expression<boolean>, ifTrue: T | Expression<T>, ifFalse: T | Expression<T>);
17 toString(): string;
18}
19/**
20 * A CEL expression that evaluates to boolean true or false based on a comparison
21 * between the value of another expression and a literal of that same type.
22 */
23export declare class CompareExpression<T extends string | number | boolean | string[]> extends Expression<boolean> {
24 cmp: "==" | "!=" | ">" | ">=" | "<" | "<=";
25 lhs: Expression<T>;
26 rhs: T | Expression<T>;
27 constructor(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", lhs: Expression<T>, rhs: T | Expression<T>);
28 toString(): string;
29 /** Returns a `TernaryExpression` which can resolve to one of two values, based on the resolution of this comparison. */
30 thenElse<retT extends string | number | boolean | string[]>(ifTrue: retT | Expression<retT>, ifFalse: retT | Expression<retT>): TernaryExpression<retT>;
31}
32/** @hidden */
33type ParamValueType = "string" | "list" | "boolean" | "int" | "float" | "secret";
34/** Create a select input from a series of values. */
35export declare function select<T>(options: T[]): SelectInput<T>;
36/** Create a select input from a map of labels to values. */
37export declare function select<T>(optionsWithLabels: Record<string, T>): SelectInput<T>;
38/** Create a multi-select input from a series of values. */
39export declare function multiSelect(options: string[]): MultiSelectInput;
40/** Create a multi-select input from map of labels to values. */
41export declare function multiSelect(options: Record<string, string>): MultiSelectInput;
42type ParamInput<T> = TextInput<T> | SelectInput<T> | (T extends string[] ? MultiSelectInput : never) | (T extends string ? ResourceInput : never);
43/**
44 * Specifies that a parameter's value should be determined by prompting the user
45 * to type it in interactively at deploy time. Input that does not match the
46 * provided validationRegex, if present, will be retried.
47 */
48export interface TextInput<T = unknown> {
49 text: {
50 example?: string;
51 /**
52 * A regular expression (or an escaped string to compile into a regular
53 * expression) which the prompted text must satisfy; the prompt will retry
54 * until input matching the regex is provided.
55 */
56 validationRegex?: string | RegExp;
57 /**
58 * A custom error message to display when retrying the prompt based on input
59 * failing to conform to the validationRegex,
60 */
61 validationErrorMessage?: string;
62 };
63}
64/**
65 * Specifies that a parameter's value should be determined by having the user
66 * select from a list containing all the project's resources of a certain
67 * type. Currently, only type:"storage.googleapis.com/Bucket" is supported.
68 */
69export interface ResourceInput {
70 resource: {
71 type: "storage.googleapis.com/Bucket";
72 };
73}
74/**
75 * Autogenerate a list of buckets in a project that a user can select from.
76 */
77export declare const BUCKET_PICKER: ResourceInput;
78/**
79 * Specifies that a parameter's value should be determined by having the user select
80 * from a list of pre-canned options interactively at deploy time.
81 */
82export interface SelectInput<T = unknown> {
83 select: {
84 options: Array<SelectOptions<T>>;
85 };
86}
87/**
88 * Specifies that a parameter's value should be determined by having the user select
89 * a subset from a list of pre-canned options interactively at deploy time.
90 * Will result in errors if used on parameters of type other than `string[]`.
91 */
92export interface MultiSelectInput {
93 multiSelect: {
94 options: Array<SelectOptions<string>>;
95 };
96}
97/**
98 * One of the options provided to a `SelectInput`, containing a value and
99 * optionally a human-readable label to display in the selection interface.
100 */
101export interface SelectOptions<T = unknown> {
102 label?: string;
103 value: T;
104}
105/** The wire representation of a parameter when it's sent to the CLI. A superset of `ParamOptions`. */
106export type ParamSpec<T extends string | number | boolean | string[]> = {
107 /** The name of the parameter which will be stored in .env files. Use UPPERCASE. */
108 name: string;
109 /** An optional default value to be used while prompting for input. Can be a literal or another parametrized expression. */
110 default?: T | Expression<T>;
111 /** An optional human-readable string to be used as a replacement for the parameter's name when prompting. */
112 label?: string;
113 /** An optional long-form description of the parameter to be displayed while prompting. */
114 description?: string;
115 /** The way in which the Firebase CLI will prompt for the value of this parameter. Defaults to a TextInput. */
116 input?: ParamInput<T>;
117};
118/**
119 * Representation of parameters for the stack over the wire.
120 *
121 * @remarks
122 * N.B: a WireParamSpec is just a ParamSpec with default expressions converted into a CEL literal
123 *
124 * @alpha
125 */
126export type WireParamSpec<T extends string | number | boolean | string[]> = {
127 name: string;
128 default?: T | string;
129 label?: string;
130 description?: string;
131 type: ParamValueType;
132 input?: ParamInput<T>;
133};
134/** Configuration options which can be used to customize the prompting behavior of a parameter. */
135export type ParamOptions<T extends string | number | boolean | string[]> = Omit<ParamSpec<T>, "name" | "type">;
136/**
137 * Represents a parametrized value that will be read from .env files if present,
138 * or prompted for by the CLI if missing. Instantiate these with the defineX
139 * methods exported by the firebase-functions/params namespace.
140 */
141export declare abstract class Param<T extends string | number | boolean | string[]> extends Expression<T> {
142 readonly name: string;
143 readonly options: ParamOptions<T>;
144 static type: ParamValueType;
145 constructor(name: string, options?: ParamOptions<T>);
146 /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
147 cmp(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", rhs: T | Expression<T>): CompareExpression<T>;
148 /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
149 equals(rhs: T | Expression<T>): CompareExpression<T>;
150 /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
151 notEquals(rhs: T | Expression<T>): CompareExpression<T>;
152 /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
153 greaterThan(rhs: T | Expression<T>): CompareExpression<T>;
154 /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
155 greaterThanOrEqualTo(rhs: T | Expression<T>): CompareExpression<T>;
156 /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
157 lessThan(rhs: T | Expression<T>): CompareExpression<T>;
158 /** Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression. */
159 lessThanOrEqualTo(rhs: T | Expression<T>): CompareExpression<T>;
160 /**
161 * Returns a parametrized expression of Boolean type, based on comparing the value of this parameter to a literal or a different expression.
162 * @deprecated A typo. Use lessThanOrEqualTo instead.
163 */
164 lessThanorEqualTo(rhs: T | Expression<T>): CompareExpression<T>;
165 toString(): string;
166}
167/**
168 * A parametrized string whose value is stored in Cloud Secret Manager
169 * instead of the local filesystem. Supply instances of SecretParams to
170 * the secrets array while defining a Function to make their values accessible
171 * during execution of that Function.
172 */
173export declare class SecretParam {
174 static type: ParamValueType;
175 name: string;
176 constructor(name: string);
177 /** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
178 value(): string;
179}
180/**
181 * A parametrized value of String type that will be read from .env files
182 * if present, or prompted for by the CLI if missing.
183 */
184export declare class StringParam extends Param<string> {
185}
186/**
187 * A parametrized value of Integer type that will be read from .env files
188 * if present, or prompted for by the CLI if missing.
189 */
190export declare class IntParam extends Param<number> {
191 static type: ParamValueType;
192}
193/**
194 * A parametrized value of Float type that will be read from .env files
195 * if present, or prompted for by the CLI if missing.
196 */
197export declare class FloatParam extends Param<number> {
198 static type: ParamValueType;
199}
200/**
201 * A parametrized value of Boolean type that will be read from .env files
202 * if present, or prompted for by the CLI if missing.
203 */
204export declare class BooleanParam extends Param<boolean> {
205 static type: ParamValueType;
206 /** @deprecated */
207 then<T extends string | number | boolean>(ifTrue: T | Expression<T>, ifFalse: T | Expression<T>): TernaryExpression<T>;
208 thenElse<T extends string | number | boolean>(ifTrue: T | Expression<T>, ifFalse: T | Expression<T>): TernaryExpression<T>;
209}
210/**
211 * A parametrized value of String[] type that will be read from .env files
212 * if present, or prompted for by the CLI if missing.
213 */
214export declare class ListParam extends Param<string[]> {
215 static type: ParamValueType;
216 /** @hidden */
217 greaterThan(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
218 /** @hidden */
219 greaterThanOrEqualTo(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
220 /** @hidden */
221 lessThan(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
222 /** @hidden */
223 lessThanorEqualTo(rhs: string[] | Expression<string[]>): CompareExpression<string[]>;
224}
225export {};