Skip to content

Commit

Permalink
Improved JSDoc types for better intellisense
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikk221 committed Sep 23, 2021
1 parent e59aad4 commit 67531f2
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Server = require('./src/components/Server.js');
const SessionEngine = require('./src/components/session/SessionEngine.js');

module.exports = {
Server: Server,
SessionEngine: SessionEngine,
Server,
SessionEngine,
compressors: uWebsockets, // This will expose all compressors from uws directly
};
66 changes: 65 additions & 1 deletion src/components/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,45 +444,109 @@ class Server {

/* Server Route Alias Methods */

/**
* @typedef {Object} RouteOptions
* @property {Array} middlewares Route specific middlewares
*/

/**
* @typedef RouteHandler
* @type {function(Request, Response):void}
*/

/**
* @param {String} pattern
* @param {RouteOptions|RouteHandler} options
* @param {RouteHandler} handler
*/
any(pattern, options, handler) {
return this._create_route('any', pattern, options, handler);
}

/**
* @param {String} pattern
* @param {RouteOptions|RouteHandler} options
* @param {RouteHandler} handler
*/
get(pattern, options, handler) {
return this._create_route('get', pattern, options, handler);
}

/**
* @param {String} pattern
* @param {RouteOptions|RouteHandler} options
* @param {RouteHandler} handler
*/
post(pattern, options, handler) {
return this._create_route('post', pattern, options, handler);
}

/**
* @param {String} pattern
* @param {RouteOptions|RouteHandler} options
* @param {RouteHandler} handler
*/
delete(pattern, options, handler) {
return this._create_route('del', pattern, options, handler);
}

/**
* @param {String} pattern
* @param {RouteOptions|RouteHandler} options
* @param {RouteHandler} handler
*/
head(pattern, options, handler) {
return this._create_route('head', pattern, options, handler);
}

/**
* @param {String} pattern
* @param {RouteOptions|RouteHandler} options
* @param {RouteHandler} handler
*/
options(pattern, options, handler) {
return this._create_route('options', pattern, options, handler);
}

/**
* @param {String} pattern
* @param {RouteOptions|RouteHandler} options
* @param {RouteHandler} handler
*/
patch(pattern, options, handler) {
return this._create_route('patch', pattern, options, handler);
}

/**
* @param {String} pattern
* @param {RouteOptions|RouteHandler} options
* @param {RouteHandler} handler
*/
trace(pattern, options, handler) {
return this._create_route('trace', pattern, options, handler);
}

/**
* @param {String} pattern
* @param {RouteOptions|RouteHandler} options
* @param {RouteHandler} handler
*/
connect(pattern, options, handler) {
return this._create_route('connect', pattern, options, handler);
}

/**
* @param {String} pattern
* @param {Object} options Websocket route options.
* @param {Object} options.compression Specifies permessage-deflate compression to use. Use one of require('hyper-express').compressors presets. Default: compressors.DISABLED
* @param {Number} options.idleTimeout Specifies interval to automatically timeout/close idle websocket connection in seconds. Default: 32
* @param {Number} options.maxBackPressure Specifies maximum websocket backpressure allowed in character length. Default: (1024 * 1024)
* @param {Number} options.maxPayloadLength Specifies maximum length allowed on incoming messages. Default: 32768 (1024 * 32)
* @returns {WebsocketRoute} Websocket route object.
*/
ws(pattern, options = {}) {
// Do not allow duplicate routes for performance/stability reasons
let method = 'ws';
const method = 'ws';
if (this.#routes[method]?.[pattern])
throw new Error(
`HyperExpress: Failed to create ${method} @ ${pattern} as duplicate routes are not allowed.`
Expand Down
7 changes: 7 additions & 0 deletions src/components/http/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Request {
}

/**
* @private
* INTERNAL METHOD! This method is an internal method and should NOT be called manually.
* This method parses initial data from uWS.Request and uWS.Response to prevent forbidden
* stack memory access errors for asynchronous usage
Expand All @@ -63,6 +64,7 @@ class Request {
}

/**
* @private
* INTERNAL METHOD! This method is an internal method and should NOT be called manually.
* This method parses request headers utilizing uWS.Request.forEach((key, value) => {})
*/
Expand All @@ -71,6 +73,7 @@ class Request {
}

/**
* @private
* INTERNAL METHOD! This method is an internal method and should NOT be called manually.
* This method parses path parameters from incoming request using a parameter key
*
Expand All @@ -88,6 +91,7 @@ class Request {
}

/**
* @private
* INTERNAL METHOD! This method is an internal method and should NOT be called manually.
* This method is used to initiate a Session object on an incoming request.
*
Expand Down Expand Up @@ -125,6 +129,7 @@ class Request {
/**
* Initiates body buffer download process.
*
* @private
* @param {Number} content_length
* @returns {Promise}
*/
Expand Down Expand Up @@ -200,6 +205,7 @@ class Request {
}

/**
* @private
* Aborts pending body buffer downloads if request is prematurely aborted.
*/
_abort_buffer() {
Expand Down Expand Up @@ -258,6 +264,7 @@ class Request {
}

/**
* @private
* Parses JSON from provided string. Resolves default_value or throws exception on failure.
*
* @param {String} string
Expand Down
4 changes: 4 additions & 0 deletions src/components/http/Response.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Response {
}

/**
* @private
* INTERNAL METHOD! This method is an internal method and should NOT be called manually.
* This method binds an abort handler which will update completed field to lock appropriate operations in Response
*/
Expand Down Expand Up @@ -161,6 +162,7 @@ class Response {
}

/**
* @private
* Executes all registered hooks (callbacks) for specified type.
*
* @param {String} type
Expand Down Expand Up @@ -223,6 +225,7 @@ class Response {
}

/**
* @private
* Returns current global byte write offset for the response.
*
* @returns {Number}
Expand Down Expand Up @@ -324,6 +327,7 @@ class Response {
}

/**
* @private
* Sends file content with appropriate content-type header based on file extension from LiveFile.
*
* @param {LiveFile} live_file
Expand Down

0 comments on commit 67531f2

Please sign in to comment.