frontend script API documentation

This commit is contained in:
azivner
2018-08-23 12:55:45 +02:00
parent 0e7372adbf
commit f5b89432a6
16 changed files with 241 additions and 125 deletions

View File

@@ -1,19 +1,31 @@
/**
* This note's representation is used in note tree and is kept in TreeCache.
* Its notable omission is the note content.
*/
class NoteShort {
constructor(treeCache, row) {
this.treeCache = treeCache;
/** @param {string} */
this.noteId = row.noteId;
/** @param {string} */
this.title = row.title;
/** @param {boolean} */
this.isProtected = row.isProtected;
/** @param {string} one of 'text', 'code', 'file' or 'render' */
this.type = row.type;
/** @param {string} content-type, e.g. "application/json" */
this.mime = row.mime;
/** @param {boolean} */
this.archived = row.archived;
this.cssClass = row.cssClass;
}
/** @returns {boolean} */
isJson() {
return this.mime === "application/json";
}
/** @returns {Promise<Array.<Branch>>} */
async getBranches() {
const branchIds = this.treeCache.parents[this.noteId].map(
parentNoteId => this.treeCache.getBranchIdByChildParent(this.noteId, parentNoteId));
@@ -21,11 +33,13 @@ class NoteShort {
return this.treeCache.getBranches(branchIds);
}
/** @returns {boolean} */
hasChildren() {
return this.treeCache.children[this.noteId]
&& this.treeCache.children[this.noteId].length > 0;
}
/** @returns {Promise<Array.<Branch>>} */
async getChildBranches() {
if (!this.treeCache.children[this.noteId]) {
return [];
@@ -37,18 +51,22 @@ class NoteShort {
return await this.treeCache.getBranches(branchIds);
}
/** @returns {Array.<string>} */
getParentNoteIds() {
return this.treeCache.parents[this.noteId] || [];
}
/** @returns {Promise<Array.<NoteShort>>} */
async getParentNotes() {
return await this.treeCache.getNotes(this.getParentNoteIds());
}
/** @returns {Array.<string>} */
getChildNoteIds() {
return this.treeCache.children[this.noteId] || [];
}
/** @returns {Promise<Array.<NoteShort>>} */
async getChildNotes() {
return await this.treeCache.getNotes(this.getChildNoteIds());
}