Skip to content

Commit

Permalink
add: jsdoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
benchambule committed Aug 22, 2024
1 parent f6e7c19 commit 621791f
Showing 1 changed file with 112 additions and 2 deletions.
114 changes: 112 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const INFORMATION = "INFORMATION";


class Message {
/**
*
* @param {string} name
*/
constructor(name){
this.name = name;
}
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()};
Expand All @@ -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()};
Expand All @@ -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}};
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 621791f

Please sign in to comment.