Skip to content

Commit f580f87

Browse files
docs(responsetemplate): cleanup + response fix
1 parent cb9ac02 commit f580f87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+889
-935
lines changed

docs/docco/src/apiclient.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
</a>
6161

6262

63-
<a class="source" href="responsetemplate.html">
64-
src/responsetemplate.ts
63+
<a class="source" href="responsetemplatemanager.html">
64+
src/responsetemplatemanager.ts
6565
</a>
6666

6767

68-
<a class="source" href="responsetemplatemanager.html">
69-
src/responsetemplatemanager.ts
68+
<a class="source" href="responsetranslator.html">
69+
src/responsetranslator.ts
7070
</a>
7171

7272

docs/docco/src/column.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
</a>
6161

6262

63-
<a class="source" href="responsetemplate.html">
64-
src/responsetemplate.ts
63+
<a class="source" href="responsetemplatemanager.html">
64+
src/responsetemplatemanager.ts
6565
</a>
6666

6767

68-
<a class="source" href="responsetemplatemanager.html">
69-
src/responsetemplatemanager.ts
68+
<a class="source" href="responsetranslator.html">
69+
src/responsetranslator.ts
7070
</a>
7171

7272

docs/docco/src/customlogger.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
</a>
6161

6262

63-
<a class="source" href="responsetemplate.html">
64-
src/responsetemplate.ts
63+
<a class="source" href="responsetemplatemanager.html">
64+
src/responsetemplatemanager.ts
6565
</a>
6666

6767

68-
<a class="source" href="responsetemplatemanager.html">
69-
src/responsetemplatemanager.ts
68+
<a class="source" href="responsetranslator.html">
69+
src/responsetranslator.ts
7070
</a>
7171

7272

docs/docco/src/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
</a>
6161

6262

63-
<a class="source" href="responsetemplate.html">
64-
src/responsetemplate.ts
63+
<a class="source" href="responsetemplatemanager.html">
64+
src/responsetemplatemanager.ts
6565
</a>
6666

6767

68-
<a class="source" href="responsetemplatemanager.html">
69-
src/responsetemplatemanager.ts
68+
<a class="source" href="responsetranslator.html">
69+
src/responsetranslator.ts
7070
</a>
7171

7272

docs/docco/src/logger.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
</a>
6161

6262

63-
<a class="source" href="responsetemplate.html">
64-
src/responsetemplate.ts
63+
<a class="source" href="responsetemplatemanager.html">
64+
src/responsetemplatemanager.ts
6565
</a>
6666

6767

68-
<a class="source" href="responsetemplatemanager.html">
69-
src/responsetemplatemanager.ts
68+
<a class="source" href="responsetranslator.html">
69+
src/responsetranslator.ts
7070
</a>
7171

7272

docs/docco/src/record.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
</a>
6161

6262

63-
<a class="source" href="responsetemplate.html">
64-
src/responsetemplate.ts
63+
<a class="source" href="responsetemplatemanager.html">
64+
src/responsetemplatemanager.ts
6565
</a>
6666

6767

68-
<a class="source" href="responsetemplatemanager.html">
69-
src/responsetemplatemanager.ts
68+
<a class="source" href="responsetranslator.html">
69+
src/responsetranslator.ts
7070
</a>
7171

7272

docs/docco/src/response.html

Lines changed: 114 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
</a>
6161

6262

63-
<a class="source" href="responsetemplate.html">
64-
src/responsetemplate.ts
63+
<a class="source" href="responsetemplatemanager.html">
64+
src/responsetemplatemanager.ts
6565
</a>
6666

6767

68-
<a class="source" href="responsetemplatemanager.html">
69-
src/responsetemplatemanager.ts
68+
<a class="source" href="responsetranslator.html">
69+
src/responsetranslator.ts
7070
</a>
7171

7272

@@ -100,12 +100,21 @@ <h1>response.ts</h1>
100100

101101
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { <span class="hljs-title class_">Column</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;./column.js&quot;</span>;
102102
<span class="hljs-keyword">import</span> { <span class="hljs-title class_">Record</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;./record.js&quot;</span>;
103-
<span class="hljs-keyword">import</span> { <span class="hljs-title class_">ResponseTemplate</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;./responsetemplate.js&quot;</span>;
103+
<span class="hljs-keyword">import</span> { <span class="hljs-title class_">ResponseTranslator</span> <span class="hljs-keyword">as</span> <span class="hljs-variable constant_">RT</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;./responsetranslator.js&quot;</span>;
104+
<span class="hljs-keyword">import</span> { <span class="hljs-title class_">ResponseParser</span> <span class="hljs-keyword">as</span> <span class="hljs-variable constant_">RP</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;./responseparser.js&quot;</span>;
104105

105106
<span class="hljs-comment">/**
106-
* Response Class inheriting from ResponseTemplate Class
107+
* Response Class
107108
*/</span>
108-
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Response</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_ inherited__">ResponseTemplate</span> {
109+
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Response</span> {
110+
<span class="hljs-comment">/**
111+
* plain API response
112+
*/</span>
113+
<span class="hljs-keyword">protected</span> <span class="hljs-attr">raw</span>: <span class="hljs-built_in">string</span>;
114+
<span class="hljs-comment">/**
115+
* hash representation of plain API response
116+
*/</span>
117+
<span class="hljs-keyword">protected</span> <span class="hljs-attr">hash</span>: <span class="hljs-built_in">any</span>;
109118
<span class="hljs-comment">/**
110119
* The API Command used within this request
111120
*/</span>
@@ -133,20 +142,9 @@ <h1>response.ts</h1>
133142
* Constructor
134143
* <span class="hljs-doctag">@param</span> raw API plain response
135144
* <span class="hljs-doctag">@param</span> cmd API command used within this request
136-
* <span class="hljs-doctag">@param</span> $ph placeholder array to get vars in response description dynamically replaced
145+
* <span class="hljs-doctag">@param</span> ph placeholder array to get vars in response description dynamically replaced
137146
*/</span>
138-
<span class="hljs-keyword">public</span> <span class="hljs-title function_">constructor</span>(<span class="hljs-params">raw: <span class="hljs-built_in">string</span>, cmd: <span class="hljs-built_in">any</span>, ph: <span class="hljs-built_in">any</span> = {}</span>) {
139-
<span class="hljs-variable language_">super</span>(raw);
140-
141-
<span class="hljs-keyword">const</span> keys = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">keys</span>(ph);
142-
keys.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">varName: <span class="hljs-built_in">string</span></span>) =&gt;</span> {
143-
<span class="hljs-variable language_">this</span>.<span class="hljs-property">raw</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">raw</span>.<span class="hljs-title function_">replace</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">RegExp</span>(<span class="hljs-string">`{<span class="hljs-subst">${varName}</span>}`</span>, <span class="hljs-string">&quot;g&quot;</span>), ph[varName]);
144-
});
145-
<span class="hljs-variable language_">this</span>.<span class="hljs-property">raw</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">raw</span>.<span class="hljs-title function_">replace</span>(<span class="hljs-regexp">/\{[A-Z_]+\}/g</span>, <span class="hljs-string">&quot;&quot;</span>);
146-
<span class="hljs-comment">/* eslint-disable constructor-super */</span>
147-
<span class="hljs-variable language_">super</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">raw</span>);
148-
<span class="hljs-comment">/* eslint-enable constructor-super */</span>
149-
147+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">constructor</span>(<span class="hljs-params">raw: <span class="hljs-built_in">string</span>, cmd: <span class="hljs-built_in">any</span> = {}, ph: <span class="hljs-built_in">any</span> = {}</span>) {
150148
<span class="hljs-variable language_">this</span>.<span class="hljs-property">command</span> = cmd;
151149
<span class="hljs-keyword">if</span> (
152150
<span class="hljs-variable language_">this</span>.<span class="hljs-property">command</span> &amp;&amp;
@@ -168,6 +166,11 @@ <h1>response.ts</h1>
168166

169167
<div class="content"><div class='highlight'><pre> <span class="hljs-variable language_">this</span>.<span class="hljs-property">command</span>.<span class="hljs-property">PASSWORD</span> = <span class="hljs-string">&quot;***&quot;</span>;
170168
}
169+
170+
<span class="hljs-variable language_">this</span>.<span class="hljs-property">raw</span> = <span class="hljs-variable constant_">RT</span>.<span class="hljs-title function_">translate</span>(raw, cmd, ph);
171+
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">raw</span>);
172+
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;-----------------------------------------&#x27;</span>);
173+
<span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span> = <span class="hljs-variable constant_">RP</span>.<span class="hljs-title function_">parse</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">raw</span>);
171174
<span class="hljs-variable language_">this</span>.<span class="hljs-property">columnkeys</span> = [];
172175
<span class="hljs-variable language_">this</span>.<span class="hljs-property">columns</span> = [];
173176
<span class="hljs-variable language_">this</span>.<span class="hljs-property">recordIndex</span> = <span class="hljs-number">0</span>;
@@ -199,6 +202,97 @@ <h1>response.ts</h1>
199202
}
200203
}
201204

205+
<span class="hljs-comment">/**
206+
* Get API response code
207+
* <span class="hljs-doctag">@returns</span> API response code
208+
*/</span>
209+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">getCode</span>(): <span class="hljs-built_in">number</span> {
210+
<span class="hljs-keyword">return</span> <span class="hljs-built_in">parseInt</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>.<span class="hljs-property">CODE</span>, <span class="hljs-number">10</span>);
211+
}
212+
213+
<span class="hljs-comment">/**
214+
* Get API response description
215+
* <span class="hljs-doctag">@returns</span> API response description
216+
*/</span>
217+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">getDescription</span>(): <span class="hljs-built_in">string</span> {
218+
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>.<span class="hljs-property">DESCRIPTION</span>;
219+
}
220+
221+
<span class="hljs-comment">/**
222+
* Get Plain API response
223+
* <span class="hljs-doctag">@returns</span> Plain API response
224+
*/</span>
225+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">getPlain</span>(): <span class="hljs-built_in">string</span> {
226+
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">raw</span>;
227+
}
228+
229+
<span class="hljs-comment">/**
230+
* Get Queuetime of API response
231+
* <span class="hljs-doctag">@returns</span> Queuetime of API response
232+
*/</span>
233+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">getQueuetime</span>(): <span class="hljs-built_in">number</span> {
234+
<span class="hljs-keyword">if</span> (<span class="hljs-title class_">Object</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>.<span class="hljs-property">hasOwnProperty</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>, <span class="hljs-string">&quot;QUEUETIME&quot;</span>)) {
235+
<span class="hljs-keyword">return</span> <span class="hljs-built_in">parseFloat</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>.<span class="hljs-property">QUEUETIME</span>);
236+
}
237+
<span class="hljs-keyword">return</span> <span class="hljs-number">0.0</span>;
238+
}
239+
240+
<span class="hljs-comment">/**
241+
* Get API response as Hash
242+
* <span class="hljs-doctag">@returns</span> API response hash
243+
*/</span>
244+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">getHash</span>(): <span class="hljs-built_in">any</span> {
245+
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>;
246+
}
247+
248+
<span class="hljs-comment">/**
249+
* Get Runtime of API response
250+
* <span class="hljs-doctag">@returns</span> Runtime of API response
251+
*/</span>
252+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">getRuntime</span>(): <span class="hljs-built_in">number</span> {
253+
<span class="hljs-keyword">if</span> (<span class="hljs-title class_">Object</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>.<span class="hljs-property">hasOwnProperty</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>, <span class="hljs-string">&quot;RUNTIME&quot;</span>)) {
254+
<span class="hljs-keyword">return</span> <span class="hljs-built_in">parseFloat</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>.<span class="hljs-property">RUNTIME</span>);
255+
}
256+
<span class="hljs-keyword">return</span> <span class="hljs-number">0.0</span>;
257+
}
258+
259+
<span class="hljs-comment">/**
260+
* Check if current API response represents an error case
261+
* API response code is an 5xx code
262+
* <span class="hljs-doctag">@returns</span> boolean result
263+
*/</span>
264+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">isError</span>(): <span class="hljs-built_in">boolean</span> {
265+
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>.<span class="hljs-property">CODE</span>.<span class="hljs-title function_">charAt</span>(<span class="hljs-number">0</span>) === <span class="hljs-string">&quot;5&quot;</span>;
266+
}
267+
268+
<span class="hljs-comment">/**
269+
* Check if current API response represents a success case
270+
* API response code is an 2xx code
271+
* <span class="hljs-doctag">@returns</span> boolean result
272+
*/</span>
273+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">isSuccess</span>(): <span class="hljs-built_in">boolean</span> {
274+
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>.<span class="hljs-property">CODE</span>.<span class="hljs-title function_">charAt</span>(<span class="hljs-number">0</span>) === <span class="hljs-string">&quot;2&quot;</span>;
275+
}
276+
277+
<span class="hljs-comment">/**
278+
* Check if current API response represents a temporary error case
279+
* API response code is an 4xx code
280+
* <span class="hljs-doctag">@returns</span> boolean result
281+
*/</span>
282+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">isTmpError</span>(): <span class="hljs-built_in">boolean</span> {
283+
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>.<span class="hljs-property">CODE</span>.<span class="hljs-title function_">charAt</span>(<span class="hljs-number">0</span>) === <span class="hljs-string">&quot;4&quot;</span>;
284+
}
285+
286+
<span class="hljs-comment">/**
287+
* Check if current operation is returned as pending
288+
* <span class="hljs-doctag">@returns</span> boolean result
289+
*/</span>
290+
<span class="hljs-keyword">public</span> <span class="hljs-title function_">isPending</span>(): <span class="hljs-built_in">boolean</span> {
291+
<span class="hljs-keyword">return</span> <span class="hljs-title class_">Object</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>.<span class="hljs-property">hasOwnProperty</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>, <span class="hljs-string">&quot;PENDING&quot;</span>)
292+
? <span class="hljs-variable language_">this</span>.<span class="hljs-property">hash</span>.<span class="hljs-property">PENDING</span> === <span class="hljs-string">&quot;1&quot;</span>
293+
: <span class="hljs-literal">false</span>;
294+
}
295+
202296
<span class="hljs-comment">/**
203297
* Add a column to the column list
204298
* <span class="hljs-doctag">@param</span> key column name

docs/docco/src/responseparser.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
</a>
6161

6262

63-
<a class="source" href="responsetemplate.html">
64-
src/responsetemplate.ts
63+
<a class="source" href="responsetemplatemanager.html">
64+
src/responsetemplatemanager.ts
6565
</a>
6666

6767

68-
<a class="source" href="responsetemplatemanager.html">
69-
src/responsetemplatemanager.ts
68+
<a class="source" href="responsetranslator.html">
69+
src/responsetranslator.ts
7070
</a>
7171

7272

0 commit comments

Comments
 (0)