@@ -10,7 +10,7 @@ import debug from './NrcDebugger.js';
10
10
11
11
12
12
/**
13
- * Description placeholder
13
+ * Main node-rest-client component
14
14
* @author aacerox
15
15
*
16
16
* @export
@@ -19,14 +19,14 @@ import debug from './NrcDebugger.js';
19
19
*/
20
20
export default class NodeRestClient extends events . EventEmitter {
21
21
/**
22
- * Description placeholder
22
+ * nrc config
23
23
* @author aacerox
24
24
*
25
25
* @type {options }
26
26
*/
27
27
#config = { } ;
28
28
/**
29
- * Description placeholder
29
+ * nrc parsers and serializers facade
30
30
* @author aacerox
31
31
*
32
32
* @type {* }
@@ -35,61 +35,69 @@ export default class NodeRestClient extends events.EventEmitter {
35
35
36
36
#apis = { } ;
37
37
38
- // public namespaces
39
38
/**
40
- * Description placeholder
39
+ * method registry
41
40
* @author aacerox
42
41
*
43
42
* @type {{} }
44
43
*/
45
- #parsers = { } ;
44
+ #methods = { } ;
45
+
46
46
/**
47
- * Description placeholder
47
+ * parsers registry
48
48
* @author aacerox
49
49
*
50
50
* @type {{} }
51
51
*/
52
- #methods = { } ;
52
+ #parsers = { } ;
53
53
54
54
/**
55
- * Description placeholder
55
+ * serializers registry
56
56
* @author aacerox
57
57
*
58
58
* @type {{} }
59
59
*/
60
60
#serializers = { } ;
61
61
62
- // default http methods
63
62
/**
64
- * Description placeholder
63
+ * private GET HTTP method where callback
64
+ * and promise logic are managed
65
65
* @author aacerox
66
66
*
67
67
* @type {* }
68
68
*/
69
69
#get;
70
+
70
71
/**
71
- * Description placeholder
72
+ * private POST HTTP method where callback
73
+ * and promise logic are managed
72
74
* @author aacerox
73
75
*
74
76
* @type {* }
75
77
*/
76
78
#post;
79
+
77
80
/**
78
- * Description placeholder
81
+ * private PUT HTTP method where callback
82
+ * and promise logic are managed
79
83
* @author aacerox
80
84
*
81
85
* @type {* }
82
86
*/
83
87
#put;
88
+
84
89
/**
85
- * Description placeholder
90
+ * private DELETE HTTP method where callback
91
+ * and promise logic are managed
86
92
* @author aacerox
87
93
*
88
94
* @type {* }
89
95
*/
90
96
#delete;
97
+
91
98
/**
92
- * Description placeholder
99
+ * private PATCH HTTP method where callback
100
+ * and promise logic are managed
93
101
* @author aacerox
94
102
*
95
103
* @type {* }
@@ -98,12 +106,13 @@ export default class NodeRestClient extends events.EventEmitter {
98
106
99
107
#usePromises;
100
108
/**
101
- * Creates an instance of NodeRestClient.
109
+ * Creates a NodeRestClient instance .
102
110
* @author aacerox
103
111
*
104
112
* @constructor
105
113
* @param {options } options to initialize client
106
- * @param {usePromises } usePromises instead of callbacks
114
+ * @param {usePromises } usePromises if true nrc will use promises
115
+ * instead of callbacks
107
116
*/
108
117
constructor (
109
118
options = {
@@ -115,7 +124,7 @@ export default class NodeRestClient extends events.EventEmitter {
115
124
} ,
116
125
) {
117
126
super ( ) ;
118
- const useProxy = options . proxy ? true : false ;
127
+ const useProxy = ! ! options . proxy ;
119
128
const useProxyTunnel =
120
129
! useProxy || options . proxy . tunnel === undefined ?
121
130
false :
@@ -131,7 +140,8 @@ export default class NodeRestClient extends events.EventEmitter {
131
140
}
132
141
133
142
/**
134
- * Description placeholder
143
+ * main initialization method where HTTP methods parsers and serializers
144
+ * are initialized
135
145
* @author aacerox
136
146
*/
137
147
#initialize( ) {
@@ -191,7 +201,7 @@ export default class NodeRestClient extends events.EventEmitter {
191
201
}
192
202
193
203
/**
194
- * Description placeholder
204
+ * returns the GET HTTP method wrapper
195
205
* @author aacerox
196
206
*
197
207
* @readonly
@@ -202,7 +212,7 @@ export default class NodeRestClient extends events.EventEmitter {
202
212
}
203
213
204
214
/**
205
- * Description placeholder
215
+ * returns the POST HTTP method wrapper
206
216
* @author aacerox
207
217
*
208
218
* @readonly
@@ -213,7 +223,7 @@ export default class NodeRestClient extends events.EventEmitter {
213
223
}
214
224
215
225
/**
216
- * Description placeholder
226
+ * returns the PUT HTTP method wrapper
217
227
* @author aacerox
218
228
*
219
229
* @readonly
@@ -224,7 +234,7 @@ export default class NodeRestClient extends events.EventEmitter {
224
234
}
225
235
226
236
/**
227
- * Description placeholder
237
+ * returns the DELETE HTTP method wrapper
228
238
* @author aacerox
229
239
*
230
240
* @readonly
@@ -235,7 +245,7 @@ export default class NodeRestClient extends events.EventEmitter {
235
245
}
236
246
237
247
/**
238
- * Description placeholder
248
+ * returns the PATCH HTTP method wrapper
239
249
* @author aacerox
240
250
*
241
251
* @readonly
@@ -246,7 +256,7 @@ export default class NodeRestClient extends events.EventEmitter {
246
256
}
247
257
248
258
/**
249
- * Description placeholder
259
+ * return all the nrc configured response parsers
250
260
* @author aacerox
251
261
*
252
262
* @readonly
@@ -257,7 +267,7 @@ export default class NodeRestClient extends events.EventEmitter {
257
267
}
258
268
259
269
/**
260
- * Description placeholder
270
+ * returns all the nrc configured request serializers
261
271
* @author aacerox
262
272
*
263
273
* @readonly
@@ -268,7 +278,7 @@ export default class NodeRestClient extends events.EventEmitter {
268
278
}
269
279
270
280
/**
271
- * Description placeholder
281
+ * returns all nrc registered methods
272
282
* @author aacerox
273
283
*
274
284
* @readonly
@@ -279,7 +289,7 @@ export default class NodeRestClient extends events.EventEmitter {
279
289
}
280
290
281
291
/**
282
- * Description placeholder
292
+ * add a new custom method to the method registry
283
293
* @author aacerox
284
294
*
285
295
* @param {* } name
@@ -289,13 +299,13 @@ export default class NodeRestClient extends events.EventEmitter {
289
299
registerMethod ( name , url , method ) {
290
300
// create method in method registry with pre-configured REST invocation
291
301
// method
292
- this . #methods[ name ] = this . #usePromises?
293
- this . #getHttpPromiseFn( url , method ) :
302
+ this . #methods[ name ] = this . #usePromises ?
303
+ this . #getHttpPromiseFn( url , method ) :
294
304
this . #getHttpCallbackFn( url , method ) ;
295
305
}
296
306
297
307
/**
298
- * Description placeholder
308
+ * unregister previously registered method
299
309
* @author aacerox
300
310
*
301
311
* @param {* } name
@@ -304,9 +314,8 @@ export default class NodeRestClient extends events.EventEmitter {
304
314
delete this . methods [ name ] ;
305
315
}
306
316
307
-
308
317
/**
309
- * Description placeholder
318
+ * returns a new HTTP method callback function
310
319
* @author aacerox
311
320
*
312
321
* @param {* } url
@@ -322,7 +331,7 @@ export default class NodeRestClient extends events.EventEmitter {
322
331
}
323
332
324
333
/**
325
- * Description placeholder
334
+ * returns a new HTTP method promise
326
335
* @author aacerox
327
336
*
328
337
* @param {* } url
@@ -343,7 +352,8 @@ export default class NodeRestClient extends events.EventEmitter {
343
352
}
344
353
345
354
/**
346
- * Description placeholder
355
+ * returns a new IOFacade object to access response parsers
356
+ * and request serializers
347
357
* @author aacerox
348
358
*
349
359
* @param {* } parserManager
0 commit comments