UNPKG

@northscaler/service-support

Version:

Artifacts that assist in writing service layers effectively

2,228 lines (675 loc) 32.6 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Global</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Global</h1> <section> <header> <h2></h2> </header> <article> <div class="container-overview"> <dl class="details"> </dl> </div> <h3 class="subsection-title">Members</h3> <h4 class="name" id="DateFormat"><span class="type-signature">(constant) </span>DateFormat<span class="type-signature"></span></h4> <div class="description"> <p>Enumeration object of date formats. Values are:</p> <ul> <li><code>ISO_8601</code></li> <li><code>UNIX_MILLISECONDS</code></li> <li><code>UNIX_SECONDS</code></li> </ul> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="enums_DateFormat.js.html">enums/DateFormat.js</a>, <a href="enums_DateFormat.js.html#line12">line 12</a> </li></ul></dd> </dl> <h4 class="name" id="ResponseStatus"><span class="type-signature">(constant) </span>ResponseStatus<span class="type-signature"></span></h4> <div class="description"> <p>Enumeration object of service response statuses. Values are:</p> <ul> <li><code>SUCCESS</code></li> <li><code>FAILURE</code></li> <li><code>PARTIAL</code></li> </ul> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="enums_ResponseStatus.js.html">enums/ResponseStatus.js</a>, <a href="enums_ResponseStatus.js.html#line12">line 12</a> </li></ul></dd> </dl> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="extractDtoFromEntity"><span class="type-signature"></span>extractDtoFromEntity<span class="signature">(entity, arg1)</span><span class="type-signature"></span></h4> <div class="description"> <p>Extracts a <a href="https://martinfowler.com/eaaCatalog/dataTransferObject.html">data transfer object (DTO)</a> from the given entity. The entity normally is an instance of a class with data properties whose names begin with the underscore character (<code>_</code>). 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 <code>Date</code>s to ISO-8601 strings and <a href="https://www.npmjs.com/package/@northscaler/enum-support"><code>Enumeration</code> instances</a> to just their <code>name</code>s. All methods found are excluded from the returned DTO. Each formatter is customizable.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>entity</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="description last"><p>The entity from which to extract a data transfer object (DTO).</p></td> </tr> <tr> <td class="name"><code>arg1</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>The argument to be deconstructed.</p> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>keyReplacementRegEx</code></td> <td class="type"> <span class="param-type">string</span> | <span class="param-type">RegExp</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> /^_/ </td> <td class="description last"><p>The key replacement regular expression given to the <code>replace</code> method of <code>String</code>; if falsey, no key replacement is performed.</p></td> </tr> <tr> <td class="name"><code>keyReplacement</code></td> <td class="type"> <span class="param-type">string</span> | <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> '' </td> <td class="description last"><p>The key replacement given to the <code>replace</code> method of <code>String</code>.</p></td> </tr> <tr> <td class="name"><code>dateFormatter</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>The formatter of <code>Date</code>s; defaults to <code>toISOString()</code> on <code>Date</code>.</p></td> </tr> <tr> <td class="name"><code>enumerationFormatter</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>The formatter of <a href="https://www.npmjs.com/package/@northscaler/enum-support"><code>Enumeration</code> instances</a>; defaults to returning the <code>name</code>.</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="service_extractDtoFromEntity.js.html">service/extractDtoFromEntity.js</a>, <a href="service_extractDtoFromEntity.js.html#line22">line 22</a> </li></ul></dd> </dl> <h4 class="name" id="formatDate"><span class="type-signature"></span>formatDate<span class="signature">(arg0<span class="signature-attributes">opt</span>, date<span class="signature-attributes">opt</span>, format<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {string|number}</span></h4> <div class="description"> <p>Formats the given date using the given <code>DateFormat</code> enum.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>arg0</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>The argument to be deconstructed.</p></td> </tr> <tr> <td class="name"><code>date</code></td> <td class="type"> <span class="param-type">Date</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>The <code>Date</code> to be formatted; if not a Date, the value is returned unchanged.</p></td> </tr> <tr> <td class="name"><code>format</code></td> <td class="type"> <span class="param-type"><a href="global.html#DateFormat">DateFormat</a></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> DateFormat.ISO_8601 </td> <td class="description last"><p>The <code>DateFormat</code> enum value to use to format <code>date</code>.</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="formatters_date-formatter.js.html">formatters/date-formatter.js</a>, <a href="formatters_date-formatter.js.html#line13">line 13</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>The formatted date.</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> | <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="formatEnumeration"><span class="type-signature"></span>formatEnumeration<span class="signature">(arg0<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> <p>Formats the given (enumeration)[https://www.npmjs.com/package/@northscaler/enum-support].</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>arg0</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"><p>The argument to be deconstructed.</p> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>enumeration</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>The <code>Enumeration</code> to be formatted.</p></td> </tr> <tr> <td class="name"><code>useName</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> true </td> <td class="description last"><p>If truey, the the <code>name</code> of the <code>Enumeration</code> will be returned, else its <code>ordinal</code>.</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="formatters_enumeration-formatter.js.html">formatters/enumeration-formatter.js</a>, <a href="formatters_enumeration-formatter.js.html#line11">line 11</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>If <code>useName</code> is truey, the <code>name</code> of the <code>Enumeration</code>, else its <code>ordinal</code>.</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="formatError"><span class="type-signature"></span>formatError<span class="signature">(arg0<span class="signature-attributes">opt</span>, error<span class="signature-attributes">opt</span>, includeStack<span class="signature-attributes">opt</span>, includeCause<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {<a href="global.html#FormattedError">FormattedError</a>}</span></h4> <div class="description"> <p>Formats the given error as a plain object.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>arg0</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>The argument to be deconstructed.</p></td> </tr> <tr> <td class="name"><code>error</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>The <code>Error</code> (or <code>Error</code>-like object) to be formatted.</p></td> </tr> <tr> <td class="name"><code>includeStack</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> true </td> <td class="description last"><p>Whether to include the <code>stack</code> property.</p></td> </tr> <tr> <td class="name"><code>includeCause</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> true </td> <td class="description last"><p>Whether to include the <code>cause</code> property.</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="formatters_error-formatter.js.html">formatters/error-formatter.js</a>, <a href="formatters_error-formatter.js.html#line22">line 22</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>The formatted error as a literal object.</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="global.html#FormattedError">FormattedError</a></span> </dd> </dl> <h4 class="name" id="serviceMethod"><span class="type-signature"></span>serviceMethod<span class="signature">(arg0<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> <p>Decorator used to execute the decorated method in a <code>try</code>/<code>catch</code> 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:</p> <pre class="prettyprint source"><code>{ data: &lt;method return value>, meta: { status: ResponseStatus.SUCCESS, elapsedMillis: n } } </code></pre> <p>If the method throws, the <code>Error</code> is caught, and formatted as a service response object with the following shape:</p> <pre class="prettyprint source"><code>{ error: { name: ..., message: ..., code: ..., info: ..., cause: ..., stack: ..., }, meta: { status: ResponseStatus.FAILURE, elapsedMillis: n } } </code></pre> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>arg0</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"><p>The argument to be deconstructed.</p> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>formatters</code></td> <td class="type"> <span class="param-type">Array.&lt;<a href="global.html#Formatter">Formatter</a>></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>Formatters to be used when formatting values in returned objects or thrown <code>Error</code>s.</p></td> </tr> <tr> <td class="name"><code>includeErrorStacks</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> true </td> <td class="description last"><p>Whether to include the <code>Error</code> <code>stack</code> property if one is thrown or there are <code>Error</code>s in the return value. Ignored if <code>formatters</code> is given.</p></td> </tr> <tr> <td class="name"><code>includeErrorCauses</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> true </td> <td class="description last"><p>Whether to include the <code>Error</code> <code>cause</code> property if one is thrown or there are <code>Error</code>s in the return value. Ignored if <code>formatters</code> is given.</p></td> </tr> <tr> <td class="name"><code>dateFormat</code></td> <td class="type"> <span class="param-type"><a href="global.html#DateFormat">DateFormat</a></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> DateFormat.ISO_8601 </td> <td class="description last"><p>The date format to use. Ignored if <code>formatters</code> is given.</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="aspects_serviceMethod.js.html">aspects/serviceMethod.js</a>, <a href="aspects_serviceMethod.js.html#line49">line 49</a> </li></ul></dd> </dl> <h3 class="subsection-title">Type Definitions</h3> <h4 class="name" id="FormattedError">FormattedError</h4> <h5>Type:</h5> <ul> <li> <span class="param-type">object</span> </li> </ul> <h5 class="subsection-title">Properties:</h5> <table class="props"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>message</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>code</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>info</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>stack</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>cause</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="formatters_error-formatter.js.html">formatters/error-formatter.js</a>, <a href="formatters_error-formatter.js.html#line3">line 3</a> </li></ul></dd> </dl> <h4 class="name" id="Formatter">Formatter</h4> <h5 class="subsection-title">Properties:</h5> <table class="props"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>type</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="description last"><p>The type of object to format if the value is <code>instanceof type</code>.</p></td> </tr> <tr> <td class="name"><code>formatter</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>The function that takes a single argument that is the instance of the <code>type</code> and returns that value formatted.</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="formatters_formatter.typedef.js.html">formatters/formatter.typedef.js</a>, <a href="formatters_formatter.typedef.js.html#line1">line 1</a> </li></ul></dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#DateFormat">DateFormat</a></li><li><a href="global.html#ResponseStatus">ResponseStatus</a></li><li><a href="global.html#extractDtoFromEntity">extractDtoFromEntity</a></li><li><a href="global.html#formatDate">formatDate</a></li><li><a href="global.html#formatEnumeration">formatEnumeration</a></li><li><a href="global.html#formatError">formatError</a></li><li><a href="global.html#serviceMethod">serviceMethod</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Sun Oct 01 2023 23:45:36 GMT+0000 (Coordinated Universal Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>