kanasimi / wikiapi

JavaScript MediaWiki API for node.js
https://kanasimi.github.io/wikiapi/
BSD 3-Clause "New" or "Revised" License
47 stars 5 forks source link

API documentation revamp (JSDoc migration) #30

Closed hugolpz closed 3 years ago

hugolpz commented 3 years ago

API actionables

hugolpz commented 3 years ago

I don't know yet how to create this man, as a readme, or by improving the in-code phrasing within wikiapi.js and test.js. But for reference, see best practice for README.md API with d3-array :

# d3.max(iterable[, accessor]) · Source. Returns .... If ..., returns.... An optional option_name does .... See also related_stuff.

I'am starting work below. Still a testing around, style and things can change. Please tell me if I'am on the right road. Help welcome. Kanasimi, I believe you have the userrights to edit my post, feel free to do so 😁 . The content below is intended to complete the current readme.md.

hugolpz commented 3 years ago

Former d3-style API proposal below.


API

# .site_name(language[,options]): {description}

# .login(username, password, API_URL): login into the target API using the provided username and password.

# .query(parameters[,options]): {description}

# .page(title[,options]): given a title, returns the page's data.

# .tracking_revisions(title,to_search[,options]): {description}

# .edit_page(title, function(d){…}[,options]): edits content of target page.

# .edit(content[,options]) {…}: to use with and after edit_page. {description}

# .move_to(move_to_title[,options]): move page to new title address.

# .move_page(move_from_title, move_to_title[,options]): moves target page to new title address.

# .purge(title[,options]): {description}

# .listen(listener[,options]listener, options) {}: to use with and after …. {description}

# .category_tree(root_category[,options]): {description}

# .search(key[,options]): {description}

# .redirects_root(title[,options]): {description}

# .redirects_here(title[,options]): {description}

# .register_redirects(template_name[,options]): {description}

# .upload(file_data): given a target file, upload it to the target wiki.

# .get_featured_content(options): {description}

# .for_each_page(page_list, for_each[,options]): {description}

# .for_each(type, title, for_each[,options]): {description}

# .data(key, property[,options]): {description}

# .convert_Chinese(text[,options]): {description}

# .run_SQL(SQL, for_each_row): {description}

# .setup_layout_elements(options): {description}

Helpers

Here we could list all options ?

_Here comes pagedata's explainer

Other tricks



Notes and Q&A

  1. Missing contents as .
  2. Missing {description}. Good practice is Given {input} does {something} or Given {input} return {something} in {format}. Format being string, object, array, number, etc.
  3. Missing get_featured_content and setup_layout_elements.
  4. Missing categoryembers :

# .categorymembers(title[,options]): returns an array of members.

  1. Missing .data() sub-methods : .entity(), .modify().

Comment

Well....I didn't expected this but I did it most of it. I thing you can complete the blanks easily. 😁

kanasimi commented 3 years ago

Maybe we can also use https://github.com/jsdoc/jsdoc ?

hugolpz commented 3 years ago

TL;DR: expand readme above will be faster. Code clean up required. Then JSdoc3 can come over.

Long version : I'am discovering JSdoc3. On the long run it's a very good idea. But as of now I lack visibility.

Your wikiapi.js code currently has (i think) a mix of comment syntaxes. I have no idea how it will play out with installing JSdoc. Aside, JSdoc renderings that I checked are not concise.

Meanwhile, the markdown API draft above is 1~2h away from becoming a clean documentation for +90% of wikiapi.js code and methods. This will be concise and elegant.

Later on, this markdown can be converted back into JSdoc3, when ready. Namely : 1) wikiapi.js comments cleaned up, 2) you/we properly learnt JSdoc3 syntaxes, 3) we know which template to use, 4) we know which project to use (JSDoc GitHub Action, jsdoc-to-markdown, other ?)

Then, some regex will help convert :

<a name="move_to" href="#move_to">#</a> .<b>move_to</b>(<i>move_to_title</i>[,<i>options</i>]): move page to new title address.
* `move_to_title`: string - target page's title.
* `options`: object - options.
  * `reason`: string - reason for the move.
  * `noredirect`: boolean
  * `movetalk`: boolean.

...into...

/**
 * @alias .move_to 
 * @description Moves page to new title address.
 * @param {String} move_to_title - target page's title.
 * @param {Object} [options] - options.
 * @param {String} [options.reason] - reason for the move.
 * @param {Boolean=1} [options.noredirect] - do not leave a redirect.
 * @param {Boolean=1} [options.movetalk] - move the talkpage as well.
 * @returns {Object} - returns (does not exist on .move_to but I put it here for demo)
 * @memberof Wikiapi.prototype
 * @example
 * result = await targetWiki.move_page('Page A', 'Page Alpha', { reason: 'Correcting name.', noredirect: true, movetalk: true });
 */
function move_to (move_to_title,options) { 
    // do stuff here
}

If you have the ability to make a quick, full JSdoc3 migration (points 1, 2, 3 and 4 above), go ahead.

But overall and given the main objective is to provide an API soon, I suggest to expand the markdown API drafted above. It will give you time to clean the wikiapi.js's comments and other improvements you see fit. Both actions prepare for a later JSdoc3 migration.

(Also since I have to catch upover my IRL todo list, I should better not be active this weekend and the coming week.)

kanasimi commented 3 years ago

try https://kanasimi.github.io/wikiapi/

hugolpz commented 3 years ago

Nice 😎

hugolpz commented 3 years ago

Saw today changes. Starts to be awesome ! Screenshot_2021-03-31_11-36-42

kanasimi commented 3 years ago

Substantial changes of documents have ended now.

hugolpz commented 3 years ago

Good work done. Close. Thank @kanasimi !