Module: services/dynamic-common

Common functions and utilities for tasks related to dynamic badges.

Source:

Members

(inner, constant) compoundValueSchema :Joi

Joi schema for validating compound value. Checks if the compound value is of type individualValueSchema, array of individualValueSchema or empty array.

Type:
  • Joi
Source:

(inner, constant) httpErrors :object

Map of error codes and their corresponding error messages.

Type:
  • object
Source:

(inner, constant) individualValueSchema :Joi

Joi schema for validating individual value. Checks if the individual value is of type string or number.

Type:
  • Joi
Source:

Methods

(inner) renderDynamicBadge(attrs) → {object}

Handles rendering concerns of dynamic badges. Determines the label of the badge according to the tag and defaultLabel. Determines the message of the badge according to the prefix, suffix and value. Sets the color of the badge to blue.

Parameters:
Name Type Description
attrs object

Refer to individual attributes

Properties
Name Type Attributes Description
defaultLabel string

default badge label

tag string <optional>

If provided then this value will be appended to the badge label, e.g. foobar@v1.23

value any

Value or array of value to be used for the badge message

prefix string <optional>

If provided then the badge message will use this value as a prefix

suffix string <optional>

If provided then the badge message will use this value as a suffix

Source:
Returns:

Badge with label, message and color properties

Type
object

(inner) transformAndValidate(attrs) → {object}

Look up the value in the data object by key and validate the value against compoundValueSchema.

Parameters:
Name Type Description
attrs object

Refer to individual attributes

Properties
Name Type Description
data object

Object containing the data for validation

key string

Key to retrieve the data from object for validation

Source:
Throws:

Error if Joi validation fails due to invalid or no schema

Type
InvalidResponse | Error
Returns:

Value if Joi validation is success

Type
object