Skip to content

Commit b7a314d

Browse files
committed
Merge branch 'launch.next' into warn_on_exec_value
2 parents a08a170 + b0acea3 commit b7a314d

File tree

1 file changed

+62
-3
lines changed

1 file changed

+62
-3
lines changed

src/params/types.ts

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as logger from "../logger";
2828
* an Expression<number> as the value of an option that normally accepts numbers.
2929
*/
3030
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. */
3232
value(): T {
3333
if (process.env.FIREBASE_DISCOVERY_DIR) {
3434
logger.warn(
@@ -47,7 +47,7 @@ export abstract class Expression<T extends string | number | boolean | string[]>
4747
throw new Error("Not implemented");
4848
}
4949

50-
// Returns the Expression's representation as a braced CEL expression.
50+
/** Returns the Expression's representation as a braced CEL expression. */
5151
toCEL(): string {
5252
return `{{ ${this.toString()} }}`;
5353
}
@@ -144,6 +144,7 @@ export class CompareExpression<
144144
return `${this.lhs} ${this.cmp} ${rhsStr}`;
145145
}
146146

147+
/** Returns a TernaryExpression which can resolve to one of two values, based on the resolution of this comparison. */
147148
then<retT extends string | number | boolean | string[]>(
148149
ifTrue: retT | Expression<retT>,
149150
ifFalse: retT | Expression<retT>
@@ -164,12 +165,20 @@ type ParamInput<T> =
164165
* Specifies that a Param's value should be determined by prompting the user
165166
* to type it in interactively at deploy-time. Input that does not match the
166167
* provided validationRegex, if present, will be retried.
167-
*
168168
*/
169169
// eslint-disable-next-line @typescript-eslint/no-unused-vars
170170
export interface TextInput<T = unknown> {
171171
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+
*/
172177
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+
*/
173182
validationErrorMessage?: string;
174183
}
175184

@@ -192,21 +201,33 @@ export interface SelectInput<T = unknown> {
192201
options: Array<SelectOptions<T>>;
193202
}
194203

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+
*/
195208
export interface SelectOptions<T = unknown> {
196209
label?: string;
197210
value: T;
198211
}
199212

213+
/** The wire representation of a Param when it's sent to the CLI. A superset of ParamOptions. */
200214
export type ParamSpec<T extends string | number | boolean | string[]> = {
215+
/** The name of the parameter which will be stored in .env files. Use UPPERCASE. */
201216
name: string;
217+
/** An optional default value to be used while prompting for input. Can be a literal or another parametrized expression. */
202218
default?: T | Expression<T>;
219+
/** An optional human-readable string to be used as a replacement for the Param's name when prompting. */
203220
label?: string;
221+
/** An optional long-form description of the Param to be displayed while prompting. */
204222
description?: string;
223+
/** @internal */
205224
type: ParamValueType;
225+
/** The way in which the Firebase CLI will prompt for the value of this Param. Defaults to a TextInput. */
206226
input?: ParamInput<T>;
207227
};
208228

209229
// N.B: a WireParamSpec is just a ParamSpec with default expressions converted into a CEL literal
230+
/** @internal */
210231
export type WireParamSpec<T extends string | number | boolean | string[]> = {
211232
name: string;
212233
default?: T | string;
@@ -216,11 +237,17 @@ export type WireParamSpec<T extends string | number | boolean | string[]> = {
216237
input?: ParamInput<T>;
217238
};
218239

240+
/** Configuration options which can be used to customize the prompting behavior of a Param. */
219241
export type ParamOptions<T extends string | number | boolean | string[]> = Omit<
220242
ParamSpec<T>,
221243
"name" | "type"
222244
>;
223245

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+
*/
224251
export abstract class Param<T extends string | number | boolean | string[]> extends Expression<T> {
225252
static type: ParamValueType = "string";
226253

@@ -233,30 +260,37 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
233260
throw new Error("Not implemented");
234261
}
235262

263+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
236264
cmp(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", rhs: T | Expression<T>) {
237265
return new CompareExpression<T>(cmp, this, rhs);
238266
}
239267

268+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
240269
equals(rhs: T | Expression<T>) {
241270
return this.cmp("==", rhs);
242271
}
243272

273+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
244274
notEquals(rhs: T | Expression<T>) {
245275
return this.cmp("!=", rhs);
246276
}
247277

278+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
248279
greaterThan(rhs: T | Expression<T>) {
249280
return this.cmp(">", rhs);
250281
}
251282

283+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
252284
greaterThanOrEqualTo(rhs: T | Expression<T>) {
253285
return this.cmp(">=", rhs);
254286
}
255287

288+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
256289
lessThan(rhs: T | Expression<T>) {
257290
return this.cmp("<", rhs);
258291
}
259292

293+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
260294
lessThanorEqualTo(rhs: T | Expression<T>) {
261295
return this.cmp("<=", rhs);
262296
}
@@ -265,6 +299,7 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
265299
return `params.${this.name}`;
266300
}
267301

302+
/** @internal */
268303
toSpec(): WireParamSpec<T> {
269304
const { default: paramDefault, ...otherOptions } = this.options;
270305

@@ -288,6 +323,12 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
288323
}
289324
}
290325

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+
*/
291332
export class SecretParam {
292333
static type: ParamValueType = "secret";
293334
name: string;
@@ -301,6 +342,7 @@ export class SecretParam {
301342
return process.env[this.name] || "";
302343
}
303344

345+
/** @internal */
304346
toSpec(): ParamSpec<string> {
305347
return {
306348
type: "secret",
@@ -309,6 +351,10 @@ export class SecretParam {
309351
}
310352
}
311353

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+
*/
312358
export class StringParam extends Param<string> {
313359
/** @internal */
314360
runtimeValue(): string {
@@ -338,6 +384,10 @@ export class InternalExpression extends Param<string> {
338384
}
339385
}
340386

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+
*/
341391
export class IntParam extends Param<number> {
342392
static type: ParamValueType = "int";
343393

@@ -347,6 +397,10 @@ export class IntParam extends Param<number> {
347397
}
348398
}
349399

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+
*/
350404
export class FloatParam extends Param<number> {
351405
static type: ParamValueType = "float";
352406

@@ -356,6 +410,10 @@ export class FloatParam extends Param<number> {
356410
}
357411
}
358412

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+
*/
359417
export class BooleanParam extends Param<boolean> {
360418
static type: ParamValueType = "boolean";
361419

@@ -369,6 +427,7 @@ export class BooleanParam extends Param<boolean> {
369427
}
370428
}
371429

430+
/** @hidden */
372431
export class ListParam extends Param<string[]> {
373432
static type: ParamValueType = "list";
374433

0 commit comments

Comments
 (0)