26
26
* an Expression<number> as the value of an option that normally accepts numbers.
27
27
*/
28
28
export abstract class Expression < T extends string | number | boolean | string [ ] > {
29
- // Returns the Expression's runtime value, based on the CLI's resolution of params.
29
+ /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
30
30
value ( ) : T {
31
31
throw new Error ( "Not implemented" ) ;
32
32
}
33
33
34
- // Returns the Expression's representation as a braced CEL expression.
34
+ /** Returns the Expression's representation as a braced CEL expression. */
35
35
toCEL ( ) : string {
36
36
return `{{ ${ this . toString ( ) } }}` ;
37
37
}
@@ -69,6 +69,7 @@ export class TernaryExpression<
69
69
this . ifFalse = ifFalse ;
70
70
}
71
71
72
+ /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
72
73
value ( ) : T {
73
74
return this . test . value ( ) ? valueOf ( this . ifTrue ) : valueOf ( this . ifFalse ) ;
74
75
}
@@ -100,6 +101,7 @@ export class CompareExpression<
100
101
this . rhs = rhs ;
101
102
}
102
103
104
+ /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
103
105
value ( ) : boolean {
104
106
const left = this . lhs . value ( ) ;
105
107
const right = valueOf ( this . rhs ) ;
@@ -126,6 +128,7 @@ export class CompareExpression<
126
128
return `${ this . lhs } ${ this . cmp } ${ rhsStr } ` ;
127
129
}
128
130
131
+ /** Returns a TernaryExpression which can resolve to one of two values, based on the resolution of this comparison. */
129
132
then < retT extends string | number | boolean | string [ ] > (
130
133
ifTrue : retT | Expression < retT > ,
131
134
ifFalse : retT | Expression < retT >
@@ -146,12 +149,20 @@ type ParamInput<T> =
146
149
* Specifies that a Param's value should be determined by prompting the user
147
150
* to type it in interactively at deploy-time. Input that does not match the
148
151
* provided validationRegex, if present, will be retried.
149
- *
150
152
*/
151
153
// eslint-disable-next-line @typescript-eslint/no-unused-vars
152
154
export interface TextInput < T = unknown > {
153
155
example ?: string ;
156
+ /**
157
+ * A regular expression (or an escaped string to compile into a regular
158
+ * expression) which the prompted text must satisfy; the prompt will retry
159
+ * until input matching the regex is provided.
160
+ */
154
161
validationRegex ?: string | RegExp ;
162
+ /**
163
+ * A custom error message to display when retrying the prompt based on input
164
+ * failing to conform to the validationRegex,
165
+ */
155
166
validationErrorMessage ?: string ;
156
167
}
157
168
@@ -174,21 +185,33 @@ export interface SelectInput<T = unknown> {
174
185
options : Array < SelectOptions < T > > ;
175
186
}
176
187
188
+ /**
189
+ * One of the options provided to a SelectInput, containing a value and
190
+ * optionally a human-readable label to display in the selection interface.
191
+ */
177
192
export interface SelectOptions < T = unknown > {
178
193
label ?: string ;
179
194
value : T ;
180
195
}
181
196
197
+ /** The wire representation of a Param when it's sent to the CLI. A superset of ParamOptions. */
182
198
export type ParamSpec < T extends string | number | boolean | string [ ] > = {
199
+ /** The name of the parameter which will be stored in .env files. Use UPPERCASE. */
183
200
name : string ;
201
+ /** An optional default value to be used while prompting for input. Can be a literal or another parametrized expression. */
184
202
default ?: T | Expression < T > ;
203
+ /** An optional human-readable string to be used as a replacement for the Param's name when prompting. */
185
204
label ?: string ;
205
+ /** An optional long-form description of the Param to be displayed while prompting. */
186
206
description ?: string ;
207
+ /** @internal */
187
208
type : ParamValueType ;
209
+ /** The way in which the Firebase CLI will prompt for the value of this Param. Defaults to a TextInput. */
188
210
input ?: ParamInput < T > ;
189
211
} ;
190
212
191
213
// N.B: a WireParamSpec is just a ParamSpec with default expressions converted into a CEL literal
214
+ /** @internal */
192
215
export type WireParamSpec < T extends string | number | boolean | string [ ] > = {
193
216
name : string ;
194
217
default ?: T | string ;
@@ -198,46 +221,60 @@ export type WireParamSpec<T extends string | number | boolean | string[]> = {
198
221
input ?: ParamInput < T > ;
199
222
} ;
200
223
224
+ /** Configuration options which can be used to customize the prompting behavior of a Param. */
201
225
export type ParamOptions < T extends string | number | boolean | string [ ] > = Omit <
202
226
ParamSpec < T > ,
203
227
"name" | "type"
204
228
> ;
205
229
230
+ /**
231
+ * Represents a parametrized value that will be read from .env files if present,
232
+ * or prompted for by the CLI if missing. Instantiate these with the defineX
233
+ * methods exported by the firebase-functions/params namespace.
234
+ */
206
235
export abstract class Param < T extends string | number | boolean | string [ ] > extends Expression < T > {
207
236
static type : ParamValueType = "string" ;
208
237
209
238
constructor ( readonly name : string , readonly options : ParamOptions < T > = { } ) {
210
239
super ( ) ;
211
240
}
212
241
242
+ /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
213
243
value ( ) : T {
214
244
throw new Error ( "Not implemented" ) ;
215
245
}
216
246
247
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
217
248
cmp ( cmp : "==" | "!=" | ">" | ">=" | "<" | "<=" , rhs : T | Expression < T > ) {
218
249
return new CompareExpression < T > ( cmp , this , rhs ) ;
219
250
}
220
251
252
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
221
253
equals ( rhs : T | Expression < T > ) {
222
254
return this . cmp ( "==" , rhs ) ;
223
255
}
224
256
257
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
225
258
notEquals ( rhs : T | Expression < T > ) {
226
259
return this . cmp ( "!=" , rhs ) ;
227
260
}
228
261
262
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
229
263
greaterThan ( rhs : T | Expression < T > ) {
230
264
return this . cmp ( ">" , rhs ) ;
231
265
}
232
266
267
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
233
268
greaterThanOrEqualTo ( rhs : T | Expression < T > ) {
234
269
return this . cmp ( ">=" , rhs ) ;
235
270
}
236
271
272
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
237
273
lessThan ( rhs : T | Expression < T > ) {
238
274
return this . cmp ( "<" , rhs ) ;
239
275
}
240
276
277
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
241
278
lessThanorEqualTo ( rhs : T | Expression < T > ) {
242
279
return this . cmp ( "<=" , rhs ) ;
243
280
}
@@ -246,6 +283,7 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
246
283
return `params.${ this . name } ` ;
247
284
}
248
285
286
+ /** @internal */
249
287
toSpec ( ) : WireParamSpec < T > {
250
288
const { default : paramDefault , ...otherOptions } = this . options ;
251
289
@@ -269,6 +307,12 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
269
307
}
270
308
}
271
309
310
+ /**
311
+ * A parametrized string whose value is stored in Cloud Secret Manager
312
+ * instead of the local filesystem. Supply instances of SecretParams to
313
+ * the secrets array while defining a Function to make their values accessible
314
+ * during execution of that Function.
315
+ */
272
316
export class SecretParam {
273
317
static type : ParamValueType = "secret" ;
274
318
name : string ;
@@ -277,10 +321,12 @@ export class SecretParam {
277
321
this . name = name ;
278
322
}
279
323
324
+ /** Returns the Expression's runtime value, based on the latest version of the Secret in Cloud Secret Manager */
280
325
value ( ) : string {
281
326
return process . env [ this . name ] || "" ;
282
327
}
283
328
329
+ /** @internal */
284
330
toSpec ( ) : ParamSpec < string > {
285
331
return {
286
332
type : "secret" ,
@@ -289,6 +335,10 @@ export class SecretParam {
289
335
}
290
336
}
291
337
338
+ /**
339
+ * A parametrized value of String type that will be read from .env files
340
+ * if present, or prompted for by the CLI if missing.
341
+ */
292
342
export class StringParam extends Param < string > {
293
343
value ( ) : string {
294
344
return process . env [ this . name ] || "" ;
@@ -316,6 +366,10 @@ export class InternalExpression extends Param<string> {
316
366
}
317
367
}
318
368
369
+ /**
370
+ * A parametrized value of Integer type that will be read from .env files
371
+ * if present, or prompted for by the CLI if missing.
372
+ */
319
373
export class IntParam extends Param < number > {
320
374
static type : ParamValueType = "int" ;
321
375
@@ -324,6 +378,10 @@ export class IntParam extends Param<number> {
324
378
}
325
379
}
326
380
381
+ /**
382
+ * A parametrized value of Float type that will be read from .env files
383
+ * if present, or prompted for by the CLI if missing.
384
+ */
327
385
export class FloatParam extends Param < number > {
328
386
static type : ParamValueType = "float" ;
329
387
@@ -332,9 +390,14 @@ export class FloatParam extends Param<number> {
332
390
}
333
391
}
334
392
393
+ /**
394
+ * A parametrized value of Boolean type that will be read from .env files
395
+ * if present, or prompted for by the CLI if missing.
396
+ */
335
397
export class BooleanParam extends Param < boolean > {
336
398
static type : ParamValueType = "boolean" ;
337
399
400
+ /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
338
401
value ( ) : boolean {
339
402
return ! ! process . env [ this . name ] && process . env [ this . name ] === "true" ;
340
403
}
@@ -344,9 +407,11 @@ export class BooleanParam extends Param<boolean> {
344
407
}
345
408
}
346
409
410
+ /** @hidden */
347
411
export class ListParam extends Param < string [ ] > {
348
412
static type : ParamValueType = "list" ;
349
413
414
+ /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
350
415
value ( ) : string [ ] {
351
416
throw new Error ( "Not implemented" ) ;
352
417
}
0 commit comments