diff --git a/index.js b/index.js index 5d1c2b7..fa8adc2 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,10 @@ const INFORMATION = "INFORMATION"; class Message { + /** + * + * @param {string} name + */ constructor(name){ this.name = name; } @@ -35,6 +39,12 @@ class Lottus { entrypoint = "main"; description = ""; + /** + * + * @param {string} location + * @param {Message|Function} result + * @returns {Lottus} + */ information(location, result){ if(typeof location !== "string" || !location){ throw new Error("location must be a non-empty string"); @@ -48,18 +58,42 @@ class Lottus { throw new Error("func must be a function or Message"); } + /** + * + * @param {string} location + * @param {Message|Function} result + * @returns {Lottus} + */ info(location, result){ return this.information(location, result); } + /** + * + * @param {string} location + * @param {Message|Function} result + * @returns {Lottus} + */ get(location, result){ return this.info(location, result); } + /** + * + * @param {string} location + * @param {Message|Function} result + * @returns {Lottus} + */ post(location, result){ return this.form(location, result); } + /** + * + * @param {string} location + * @param {Message|Function} result + * @returns {Lottus} + */ form(location, result){ if(typeof location !== "string" || !location){ throw new Error("location must be a non-empty string"); @@ -73,6 +107,13 @@ class Lottus { throw new Error("result must be a function or Message"); } + /** + * + * @param {string} location + * @param {Message|Function} info + * @param {Message|Function} proc + * @returns {Lottus} + */ at(location, info, proc){ this.info(location, info); this.form(location, proc); @@ -90,6 +131,13 @@ class Lottus { } } + /** + * + * @param {string} location + * @param {Request} request + * @param {string} method + * @returns + */ async redirect(location, request, method = INFORMATION){ if(this.debug){ console.log("Lottus.redirect input", method, location, request); @@ -135,6 +183,12 @@ class Lottus { return result; } + /** + * + * @param {Request} request + * @param {Message} last_message + * @returns {Message} + */ async process(request, last_message){ if(this.debug){ console.log("Lottus.process input", request); @@ -165,6 +219,12 @@ class Lottus { return message.form?FORM:INFORMATION; } + /** + * + * @param {Request} request + * @param {Message} message + * @returns {Message} + */ async process_request(request, message){ if(this.debug){ console.log("Lottus.process_request input", request, message); @@ -206,7 +266,12 @@ Message.prototype.header = ""; Message.prototype.body = ""; Message.prototype.footer = "Powered by Lottus"; - +/** + * + * @param {string} label + * @param {string} next + * @param {object} params + */ Message.prototype.addAutoOption = function addAutoOption(label, next, params){ if(!this.form){ this.form = {options: new Map()}; @@ -226,6 +291,13 @@ Message.prototype.addAutoOption = function addAutoOption(label, next, params){ } +/** + * + * @param {string} key + * @param {string} label + * @param {string} next + * @param {object} params + */ Message.prototype.addOption = function addOption(key, label, next, params){ if(!this.form){ this.form = {options: new Map()}; @@ -246,7 +318,12 @@ Message.prototype.addOption = function addOption(key, label, next, params){ this.form.options.set(key.toString(), {label, next, params}); } - +/** + * + * @param {string} name + * @param {string} type + * @param {string} next + */ Message.prototype.addInput = function addInput(name, type, next){ if(!this.form){ this.form = {input: {name, type, next}}; @@ -258,7 +335,18 @@ Message.prototype.addInput = function addInput(name, type, next){ } +/** + * + * @param {Lottus} bot + * @returns {Function} + */ function create_options_processor(bot){ + /** + * + * @param {Request} req + * @param {Message} res + * @returns {Message} + */ async function create_options_processor(req, res){ const options = req.form?.options; @@ -286,7 +374,18 @@ function create_options_processor(bot){ } +/** + * + * @param {Lottus} bot + * @returns {Function} + */ function create_input_processor(bot){ + /** + * + * @param {Request} req + * @param {Message} res + * @returns {Message} + */ async function input_processor(req, res){ const input = req.form?.input; @@ -305,7 +404,18 @@ function create_input_processor(bot){ } +/** + * + * @param {Lottus} bot + * @returns {Function} + */ function create_form_processor(bot){ + /** + * + * @param {Request} req + * @param {Message} res + * @returns {Message} + */ async function form_processor(req, res){ const options = req.form?.options; const input = req.form?.input;