UNPKG

@barchart/common-js

Version:
63 lines (62 loc) 1.57 kB
/** * Encapsulates definition of a parameter -- that is, its name and * its value. Parameters are used in request paths, request bodies, * querystrings, and as request headers. * * @public */ export default class Parameter { /** * @param {string} description * @param {string} key * @param {parameterValueCallback} extractor * @param {boolean=} optional */ constructor(description: string, key: string, extractor: parameterValueCallback, optional?: boolean | undefined); /** * The human-readable description of the parameter. * * @public * @returns {string} */ public get description(): string; /** * The name of the parameter. * * @public * @returns {string} */ public get key(): string; /** * A function for extracting the parameter's value. * * @public * @returns {parameterValueCallback} */ public get extractor(): parameterValueCallback; /** * Indicates if the parameter is required. * * @public * @returns {boolean} */ public get optional(): boolean; /** * Throws an {@link Error} if the instance is invalid. * * @public */ public validate(): void; /** * Returns a string representation. * * @public * @returns {string} */ public toString(): string; #private; } /** * A function that, when passed the request's payload, returns a parameter's value. */ export type parameterValueCallback = (payload: object) => Promise<string>;