Members
(constant) DateFormat
Enumeration object of date formats. Values are:
ISO_8601UNIX_MILLISECONDSUNIX_SECONDS
- Source:
(constant) ResponseStatus
Enumeration object of service response statuses. Values are:
SUCCESSFAILUREPARTIAL
- Source:
Methods
extractDtoFromEntity(entity, arg1)
Extracts a data transfer object (DTO) from the given entity.
The entity normally is an instance of a class with data properties whose names begin with the underscore character (_).
By default, this will descend recursively through the given object and drop the leading underscore prefix from its keys and convert any convertible values, mainly Dates to ISO-8601 strings and Enumeration instances to just their names.
All methods found are excluded from the returned DTO.
Each formatter is customizable.
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
entity |
* | The entity from which to extract a data transfer object (DTO). |
|||||||||||||||||||||||||
arg1 |
object | The argument to be deconstructed. Properties
|
- Source:
formatDate(arg0opt, dateopt, formatopt) → {string|number}
Formats the given date using the given DateFormat enum.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
arg0 |
object |
<optional> |
The argument to be deconstructed. |
|
date |
Date |
<optional> |
The |
|
format |
DateFormat |
<optional> |
DateFormat.ISO_8601 | The |
- Source:
Returns:
The formatted date.
- Type
- string | number
formatEnumeration(arg0opt) → {string}
Formats the given (enumeration)[https://www.npmjs.com/package/@northscaler/enum-support].
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
arg0 |
object |
<optional> |
The argument to be deconstructed. Properties
|
Returns:
If useName is truey, the name of the Enumeration, else its ordinal.
- Type
- string
formatError(arg0opt, erroropt, includeStackopt, includeCauseopt) → {FormattedError}
Formats the given error as a plain object.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
arg0 |
object |
<optional> |
The argument to be deconstructed. |
|
error |
object |
<optional> |
The |
|
includeStack |
boolean |
<optional> |
true | Whether to include the |
includeCause |
boolean |
<optional> |
true | Whether to include the |
- Source:
Returns:
The formatted error as a literal object.
- Type
- FormattedError
serviceMethod(arg0opt)
Decorator used to execute the decorated method in a try/catch block.
Use on service class methods only.
If the method returns normally, the return value is wrapped in a service response object with the following shape:
{
data: <method return value>,
meta: {
status: ResponseStatus.SUCCESS,
elapsedMillis: n
}
}
If the method throws, the Error is caught, and formatted as a service response object with the following shape:
{
error: {
name: ...,
message: ...,
code: ...,
info: ...,
cause: ...,
stack: ...,
},
meta: {
status: ResponseStatus.FAILURE,
elapsedMillis: n
}
}
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
arg0 |
object |
<optional> |
The argument to be deconstructed. Properties
|
- Source:
Type Definitions
FormattedError
Type:
- object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
name |
string |
<optional> |
|
message |
string |
<optional> |
|
code |
string |
<optional> |
|
info |
* |
<optional> |
|
stack |
string |
<optional> |
|
cause |
object |
<optional> |
- Source:
Formatter
Properties:
| Name | Type | Description |
|---|---|---|
type |
* | The type of object to format if the value is |
formatter |
function | The function that takes a single argument that is the instance of the |
- Source: