Skip to content

Commit b0acea3

Browse files
authored
Add jsdoc comments to the params types and fields (#1258)
1 parent 9a7b280 commit b0acea3

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

src/params/types.ts

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
* an Expression<number> as the value of an option that normally accepts numbers.
2727
*/
2828
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. */
3030
value(): T {
3131
throw new Error("Not implemented");
3232
}
3333

34-
// Returns the Expression's representation as a braced CEL expression.
34+
/** Returns the Expression's representation as a braced CEL expression. */
3535
toCEL(): string {
3636
return `{{ ${this.toString()} }}`;
3737
}
@@ -69,6 +69,7 @@ export class TernaryExpression<
6969
this.ifFalse = ifFalse;
7070
}
7171

72+
/** Returns the Expression's runtime value, based on the CLI's resolution of params. */
7273
value(): T {
7374
return this.test.value() ? valueOf(this.ifTrue) : valueOf(this.ifFalse);
7475
}
@@ -100,6 +101,7 @@ export class CompareExpression<
100101
this.rhs = rhs;
101102
}
102103

104+
/** Returns the Expression's runtime value, based on the CLI's resolution of params. */
103105
value(): boolean {
104106
const left = this.lhs.value();
105107
const right = valueOf(this.rhs);
@@ -126,6 +128,7 @@ export class CompareExpression<
126128
return `${this.lhs} ${this.cmp} ${rhsStr}`;
127129
}
128130

131+
/** Returns a TernaryExpression which can resolve to one of two values, based on the resolution of this comparison. */
129132
then<retT extends string | number | boolean | string[]>(
130133
ifTrue: retT | Expression<retT>,
131134
ifFalse: retT | Expression<retT>
@@ -146,12 +149,20 @@ type ParamInput<T> =
146149
* Specifies that a Param's value should be determined by prompting the user
147150
* to type it in interactively at deploy-time. Input that does not match the
148151
* provided validationRegex, if present, will be retried.
149-
*
150152
*/
151153
// eslint-disable-next-line @typescript-eslint/no-unused-vars
152154
export interface TextInput<T = unknown> {
153155
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+
*/
154161
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+
*/
155166
validationErrorMessage?: string;
156167
}
157168

@@ -174,21 +185,33 @@ export interface SelectInput<T = unknown> {
174185
options: Array<SelectOptions<T>>;
175186
}
176187

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+
*/
177192
export interface SelectOptions<T = unknown> {
178193
label?: string;
179194
value: T;
180195
}
181196

197+
/** The wire representation of a Param when it's sent to the CLI. A superset of ParamOptions. */
182198
export type ParamSpec<T extends string | number | boolean | string[]> = {
199+
/** The name of the parameter which will be stored in .env files. Use UPPERCASE. */
183200
name: string;
201+
/** An optional default value to be used while prompting for input. Can be a literal or another parametrized expression. */
184202
default?: T | Expression<T>;
203+
/** An optional human-readable string to be used as a replacement for the Param's name when prompting. */
185204
label?: string;
205+
/** An optional long-form description of the Param to be displayed while prompting. */
186206
description?: string;
207+
/** @internal */
187208
type: ParamValueType;
209+
/** The way in which the Firebase CLI will prompt for the value of this Param. Defaults to a TextInput. */
188210
input?: ParamInput<T>;
189211
};
190212

191213
// N.B: a WireParamSpec is just a ParamSpec with default expressions converted into a CEL literal
214+
/** @internal */
192215
export type WireParamSpec<T extends string | number | boolean | string[]> = {
193216
name: string;
194217
default?: T | string;
@@ -198,46 +221,60 @@ export type WireParamSpec<T extends string | number | boolean | string[]> = {
198221
input?: ParamInput<T>;
199222
};
200223

224+
/** Configuration options which can be used to customize the prompting behavior of a Param. */
201225
export type ParamOptions<T extends string | number | boolean | string[]> = Omit<
202226
ParamSpec<T>,
203227
"name" | "type"
204228
>;
205229

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

209238
constructor(readonly name: string, readonly options: ParamOptions<T> = {}) {
210239
super();
211240
}
212241

242+
/** Returns the Expression's runtime value, based on the CLI's resolution of params. */
213243
value(): T {
214244
throw new Error("Not implemented");
215245
}
216246

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

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

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

262+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
229263
greaterThan(rhs: T | Expression<T>) {
230264
return this.cmp(">", rhs);
231265
}
232266

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

272+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
237273
lessThan(rhs: T | Expression<T>) {
238274
return this.cmp("<", rhs);
239275
}
240276

277+
/** Returns a parametrized expression of Boolean type, based on comparing the value of this param to a literal or a different expression. */
241278
lessThanorEqualTo(rhs: T | Expression<T>) {
242279
return this.cmp("<=", rhs);
243280
}
@@ -246,6 +283,7 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
246283
return `params.${this.name}`;
247284
}
248285

286+
/** @internal */
249287
toSpec(): WireParamSpec<T> {
250288
const { default: paramDefault, ...otherOptions } = this.options;
251289

@@ -269,6 +307,12 @@ export abstract class Param<T extends string | number | boolean | string[]> exte
269307
}
270308
}
271309

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+
*/
272316
export class SecretParam {
273317
static type: ParamValueType = "secret";
274318
name: string;
@@ -277,10 +321,12 @@ export class SecretParam {
277321
this.name = name;
278322
}
279323

324+
/** Returns the Expression's runtime value, based on the latest version of the Secret in Cloud Secret Manager */
280325
value(): string {
281326
return process.env[this.name] || "";
282327
}
283328

329+
/** @internal */
284330
toSpec(): ParamSpec<string> {
285331
return {
286332
type: "secret",
@@ -289,6 +335,10 @@ export class SecretParam {
289335
}
290336
}
291337

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+
*/
292342
export class StringParam extends Param<string> {
293343
value(): string {
294344
return process.env[this.name] || "";
@@ -316,6 +366,10 @@ export class InternalExpression extends Param<string> {
316366
}
317367
}
318368

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

@@ -324,6 +378,10 @@ export class IntParam extends Param<number> {
324378
}
325379
}
326380

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

@@ -332,9 +390,14 @@ export class FloatParam extends Param<number> {
332390
}
333391
}
334392

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

400+
/** Returns the Expression's runtime value, based on the CLI's resolution of params. */
338401
value(): boolean {
339402
return !!process.env[this.name] && process.env[this.name] === "true";
340403
}
@@ -344,9 +407,11 @@ export class BooleanParam extends Param<boolean> {
344407
}
345408
}
346409

410+
/** @hidden */
347411
export class ListParam extends Param<string[]> {
348412
static type: ParamValueType = "list";
349413

414+
/** Returns the Expression's runtime value, based on the CLI's resolution of params. */
350415
value(): string[] {
351416
throw new Error("Not implemented");
352417
}

0 commit comments

Comments
 (0)