Skip to content

Commit

Permalink
chore: add code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aacerox committed Aug 21, 2023
1 parent dd22aad commit 39ea5cc
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 99 deletions.
80 changes: 45 additions & 35 deletions lib/NodeRestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import debug from './NrcDebugger.js';


/**
* Description placeholder
* Main node-rest-client component
* @author aacerox
*
* @export
Expand All @@ -19,14 +19,14 @@ import debug from './NrcDebugger.js';
*/
export default class NodeRestClient extends events.EventEmitter {
/**
* Description placeholder
* nrc config
* @author aacerox
*
* @type {options}
*/
#config = {};
/**
* Description placeholder
* nrc parsers and serializers facade
* @author aacerox
*
* @type {*}
Expand All @@ -35,61 +35,69 @@ export default class NodeRestClient extends events.EventEmitter {

#apis = {};

// public namespaces
/**
* Description placeholder
* method registry
* @author aacerox
*
* @type {{}}
*/
#parsers = {};
#methods = {};

/**
* Description placeholder
* parsers registry
* @author aacerox
*
* @type {{}}
*/
#methods = {};
#parsers = {};

/**
* Description placeholder
* serializers registry
* @author aacerox
*
* @type {{}}
*/
#serializers = {};

// default http methods
/**
* Description placeholder
* private GET HTTP method where callback
* and promise logic are managed
* @author aacerox
*
* @type {*}
*/
#get;

/**
* Description placeholder
* private POST HTTP method where callback
* and promise logic are managed
* @author aacerox
*
* @type {*}
*/
#post;

/**
* Description placeholder
* private PUT HTTP method where callback
* and promise logic are managed
* @author aacerox
*
* @type {*}
*/
#put;

/**
* Description placeholder
* private DELETE HTTP method where callback
* and promise logic are managed
* @author aacerox
*
* @type {*}
*/
#delete;

/**
* Description placeholder
* private PATCH HTTP method where callback
* and promise logic are managed
* @author aacerox
*
* @type {*}
Expand All @@ -98,12 +106,13 @@ export default class NodeRestClient extends events.EventEmitter {

#usePromises;
/**
* Creates an instance of NodeRestClient.
* Creates a NodeRestClient instance.
* @author aacerox
*
* @constructor
* @param {options} options to initialize client
* @param {usePromises} usePromises instead of callbacks
* @param {usePromises} usePromises if true nrc will use promises
* instead of callbacks
*/
constructor(
options = {
Expand All @@ -115,7 +124,7 @@ export default class NodeRestClient extends events.EventEmitter {
},
) {
super();
const useProxy = options.proxy ? true : false;
const useProxy = !!options.proxy;
const useProxyTunnel =
!useProxy || options.proxy.tunnel === undefined ?
false :
Expand All @@ -131,7 +140,8 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* main initialization method where HTTP methods parsers and serializers
* are initialized
* @author aacerox
*/
#initialize() {
Expand Down Expand Up @@ -191,7 +201,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* returns the GET HTTP method wrapper
* @author aacerox
*
* @readonly
Expand All @@ -202,7 +212,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* returns the POST HTTP method wrapper
* @author aacerox
*
* @readonly
Expand All @@ -213,7 +223,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* returns the PUT HTTP method wrapper
* @author aacerox
*
* @readonly
Expand All @@ -224,7 +234,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* returns the DELETE HTTP method wrapper
* @author aacerox
*
* @readonly
Expand All @@ -235,7 +245,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* returns the PATCH HTTP method wrapper
* @author aacerox
*
* @readonly
Expand All @@ -246,7 +256,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* return all the nrc configured response parsers
* @author aacerox
*
* @readonly
Expand All @@ -257,7 +267,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* returns all the nrc configured request serializers
* @author aacerox
*
* @readonly
Expand All @@ -268,7 +278,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* returns all nrc registered methods
* @author aacerox
*
* @readonly
Expand All @@ -279,7 +289,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* add a new custom method to the method registry
* @author aacerox
*
* @param {*} name
Expand All @@ -289,13 +299,13 @@ export default class NodeRestClient extends events.EventEmitter {
registerMethod(name, url, method) {
// create method in method registry with pre-configured REST invocation
// method
this.#methods[name] = this.#usePromises?
this.#getHttpPromiseFn(url, method):
this.#methods[name] = this.#usePromises ?
this.#getHttpPromiseFn(url, method) :
this.#getHttpCallbackFn(url, method);
}

/**
* Description placeholder
* unregister previously registered method
* @author aacerox
*
* @param {*} name
Expand All @@ -304,9 +314,8 @@ export default class NodeRestClient extends events.EventEmitter {
delete this.methods[name];
}


/**
* Description placeholder
* returns a new HTTP method callback function
* @author aacerox
*
* @param {*} url
Expand All @@ -322,7 +331,7 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* returns a new HTTP method promise
* @author aacerox
*
* @param {*} url
Expand All @@ -343,7 +352,8 @@ export default class NodeRestClient extends events.EventEmitter {
}

/**
* Description placeholder
* returns a new IOFacade object to access response parsers
* and request serializers
* @author aacerox
*
* @param {*} parserManager
Expand Down
13 changes: 2 additions & 11 deletions lib/NrcClientRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ import events from 'events';
*/
export default class ClientRequest extends events.EventEmitter {
/**
* Creates an instance of ClientRequest.
* @author aacerox
*
* @constructor
*/
constructor() {
super();
}
/**
* Description placeholder
* finalize current http request
* @author aacerox
*/
end() {
Expand All @@ -31,7 +22,7 @@ export default class ClientRequest extends events.EventEmitter {
}
}
/**
* Description placeholder
* set new http request
* @author aacerox
*
* @param {*} req
Expand Down
Loading

0 comments on commit 39ea5cc

Please sign in to comment.