@@ -28,7 +28,7 @@ import * as logger from "../logger";
28
28
* an Expression<number> as the value of an option that normally accepts numbers.
29
29
*/
30
30
export abstract class Expression < T extends string | number | boolean | string [ ] > {
31
- // Returns the Expression's runtime value, based on the CLI's resolution of params.
31
+ /** Returns the Expression's runtime value, based on the CLI's resolution of params. */
32
32
value ( ) : T {
33
33
if ( process . env . FIREBASE_DISCOVERY_DIR ) {
34
34
logger . warn (
@@ -47,7 +47,7 @@ export abstract class Expression<T extends string | number | boolean | string[]>
47
47
throw new Error ( "Not implemented" ) ;
48
48
}
49
49
50
- // Returns the Expression's representation as a braced CEL expression.
50
+ /** Returns the Expression's representation as a braced CEL expression. */
51
51
toCEL ( ) : string {
52
52
return `{{ ${ this . toString ( ) } }}` ;
53
53
}
@@ -144,6 +144,7 @@ export class CompareExpression<
144
144
return `${ this . lhs } ${ this . cmp } ${ rhsStr } ` ;
145
145
}
146
146
147
+ /** Returns a TernaryExpression which can resolve to one of two values, based on the resolution of this comparison. */
147
148
then < retT extends string | number | boolean | string [ ] > (
148
149
ifTrue : retT | Expression < retT > ,
149
150
ifFalse : retT | Expression < retT >
@@ -164,12 +165,20 @@ type ParamInput<T> =
164
165
* Specifies that a Param's value should be determined by prompting the user
165
166
* to type it in interactively at deploy-time. Input that does not match the
166
167
* provided validationRegex, if present, will be retried.
167
- *
168
168
*/
169
169
// eslint-disable-next-line @typescript-eslint/no-unused-vars
170
170
export interface TextInput < T = unknown > {
171
171
example ?: string ;
172
+ /**
173
+ * A regular expression (or an escaped string to compile into a regular
174
+ * expression) which the prompted text must satisfy; the prompt will retry
175
+ * until input matching the regex is provided.
176
+ */
172
177
validationRegex ?: string | RegExp ;
178
+ /**
179
+ * A custom error message to display when retrying the prompt based on input
180
+ * failing to conform to the validationRegex,
181
+ */
173
182
validationErrorMessage ?: string ;
174
183
}
175
184
@@ -192,21 +201,33 @@ export interface SelectInput<T = unknown> {
192
201
options : Array < SelectOptions < T > > ;
193
202
}
194
203
204
+ /**
205
+ * One of the options provided to a SelectInput, containing a value and
206
+ * optionally a human-readable label to display in the selection interface.
207
+ */
195
208
export interface SelectOptions < T = unknown > {
196
209
label ?: string ;
197
210
value : T ;
198
211
}
199
212
213
+ /** The wire representation of a Param when it's sent to the CLI. A superset of ParamOptions. */
200
214
export type ParamSpec < T extends string | number | boolean | string [ ] > = {
215
+ /** The name of the parameter which will be stored in .env files. Use UPPERCASE. */
201
216
name : string ;
217
+ /** An optional default value to be used while prompting for input. Can be a literal or another parametrized expression. */
202
218
default ?: T | Expression < T > ;
219
+ /** An optional human-readable string to be used as a replacement for the Param's name when prompting. */
203
220
label ?: string ;
221
+ /** An optional long-form description of the Param to be displayed while prompting. */
204
222
description ?: string ;
223
+ /** @internal */
205
224
type : ParamValueType ;
225
+ /** The way in which the Firebase CLI will prompt for the value of this Param. Defaults to a TextInput. */
206
226
input ?: ParamInput < T > ;
207
227
} ;
208
228
209
229
// N.B: a WireParamSpec is just a ParamSpec with default expressions converted into a CEL literal
230
+ /** @internal */
210
231
export type WireParamSpec < T extends string | number | boolean | string [ ] > = {
211
232
name : string ;
212
233
default ?: T | string ;
@@ -216,11 +237,17 @@ export type WireParamSpec<T extends string | number | boolean | string[]> = {
216
237
input ?: ParamInput < T > ;
217
238
} ;
218
239
240
+ /** Configuration options which can be used to customize the prompting behavior of a Param. */
219
241
export type ParamOptions < T extends string | number | boolean | string [ ] > = Omit <
220
242
ParamSpec < T > ,
221
243
"name" | "type"
222
244
> ;
223
245
246
+ /**
247
+ * Represents a parametrized value that will be read from .env files if present,
248
+ * or prompted for by the CLI if missing. Instantiate these with the defineX
249
+ * methods exported by the firebase-functions/params namespace.
250
+ */
224
251
export abstract class Param < T extends string | number | boolean | string [ ] > extends Expression < T > {
225
252
static type : ParamValueType = "string" ;
226
253
@@ -233,30 +260,37 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
233
260
throw new Error ( "Not implemented" ) ;
234
261
}
235
262
263
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
236
264
cmp ( cmp : "==" | "!=" | ">" | ">=" | "<" | "<=" , rhs : T | Expression < T > ) {
237
265
return new CompareExpression < T > ( cmp , this , rhs ) ;
238
266
}
239
267
268
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
240
269
equals ( rhs : T | Expression < T > ) {
241
270
return this . cmp ( "==" , rhs ) ;
242
271
}
243
272
273
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
244
274
notEquals ( rhs : T | Expression < T > ) {
245
275
return this . cmp ( "!=" , rhs ) ;
246
276
}
247
277
278
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
248
279
greaterThan ( rhs : T | Expression < T > ) {
249
280
return this . cmp ( ">" , rhs ) ;
250
281
}
251
282
283
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
252
284
greaterThanOrEqualTo ( rhs : T | Expression < T > ) {
253
285
return this . cmp ( ">=" , rhs ) ;
254
286
}
255
287
288
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
256
289
lessThan ( rhs : T | Expression < T > ) {
257
290
return this . cmp ( "<" , rhs ) ;
258
291
}
259
292
293
+ /** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
260
294
lessThanorEqualTo ( rhs : T | Expression < T > ) {
261
295
return this . cmp ( "<=" , rhs ) ;
262
296
}
@@ -265,6 +299,7 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
265
299
return `params.${ this . name } ` ;
266
300
}
267
301
302
+ /** @internal */
268
303
toSpec ( ) : WireParamSpec < T > {
269
304
const { default : paramDefault , ...otherOptions } = this . options ;
270
305
@@ -288,6 +323,12 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
288
323
}
289
324
}
290
325
326
+ /**
327
+ * A parametrized string whose value is stored in Cloud Secret Manager
328
+ * instead of the local filesystem. Supply instances of SecretParams to
329
+ * the secrets array while defining a Function to make their values accessible
330
+ * during execution of that Function.
331
+ */
291
332
export class SecretParam {
292
333
static type : ParamValueType = "secret" ;
293
334
name : string ;
@@ -301,6 +342,7 @@ export class SecretParam {
301
342
return process . env [ this . name ] || "" ;
302
343
}
303
344
345
+ /** @internal */
304
346
toSpec ( ) : ParamSpec < string > {
305
347
return {
306
348
type : "secret" ,
@@ -309,6 +351,10 @@ export class SecretParam {
309
351
}
310
352
}
311
353
354
+ /**
355
+ * A parametrized value of String type that will be read from .env files
356
+ * if present, or prompted for by the CLI if missing.
357
+ */
312
358
export class StringParam extends Param < string > {
313
359
/** @internal */
314
360
runtimeValue ( ) : string {
@@ -338,6 +384,10 @@ export class InternalExpression extends Param<string> {
338
384
}
339
385
}
340
386
387
+ /**
388
+ * A parametrized value of Integer type that will be read from .env files
389
+ * if present, or prompted for by the CLI if missing.
390
+ */
341
391
export class IntParam extends Param < number > {
342
392
static type : ParamValueType = "int" ;
343
393
@@ -347,6 +397,10 @@ export class IntParam extends Param<number> {
347
397
}
348
398
}
349
399
400
+ /**
401
+ * A parametrized value of Float type that will be read from .env files
402
+ * if present, or prompted for by the CLI if missing.
403
+ */
350
404
export class FloatParam extends Param < number > {
351
405
static type : ParamValueType = "float" ;
352
406
@@ -356,6 +410,10 @@ export class FloatParam extends Param<number> {
356
410
}
357
411
}
358
412
413
+ /**
414
+ * A parametrized value of Boolean type that will be read from .env files
415
+ * if present, or prompted for by the CLI if missing.
416
+ */
359
417
export class BooleanParam extends Param < boolean > {
360
418
static type : ParamValueType = "boolean" ;
361
419
@@ -369,6 +427,7 @@ export class BooleanParam extends Param<boolean> {
369
427
}
370
428
}
371
429
430
+ /** @hidden */
372
431
export class ListParam extends Param < string [ ] > {
373
432
static type : ParamValueType = "list" ;
374
433
0 commit comments