Source: note_short.js

/**
 * This note's representation is used in note tree and is kept in Froca.
 * Its notable omission is the note content.
 */
class NoteShort {
    constructor(froca, row) {
        this.froca = froca;
        /** @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.froca.parents[this.noteId].map(
            parentNoteId => this.froca.getBranchIdByChildParent(this.noteId, parentNoteId));

        return this.froca.getBranches(branchIds);
    }

    /** @returns {boolean} */
    hasChildren() {
        return this.froca.children[this.noteId]
            && this.froca.children[this.noteId].length > 0;
    }

    /** @returns {Promise<Array.<Branch>>} */
    async getChildBranches() {
        if (!this.froca.children[this.noteId]) {
            return [];
        }

        const branchIds = this.froca.children[this.noteId].map(
            childNoteId => this.froca.getBranchIdByChildParent(childNoteId, this.noteId));

        return await this.froca.getBranches(branchIds);
    }

    /** @returns {Array.<string>} */
    getParentNoteIds() {
        return this.froca.parents[this.noteId] || [];
    }

    /** @returns {Promise<Array.<NoteShort>>} */
    async getParentNotes() {
        return await this.froca.getNotes(this.getParentNoteIds());
    }

    /** @returns {Array.<string>} */
    getChildNoteIds() {
        return this.froca.children[this.noteId] || [];
    }

    /** @returns {Promise<Array.<NoteShort>>} */
    async getChildNotes() {
        return await this.froca.getNotes(this.getChildNoteIds());
    }

    get toString() {
        return `Note(noteId=${this.noteId}, title=${this.title})`;
    }

    get dto() {
        const dto = Object.assign({}, this);
        delete dto.froca;
        delete dto.archived;

        return dto;
    }
}

export default NoteShort;