diff --git a/src/share/shaca/entities/sbranch.js b/src/share/shaca/entities/sbranch.ts similarity index 72% rename from src/share/shaca/entities/sbranch.js rename to src/share/shaca/entities/sbranch.ts index a6f2ac13a..4d906d750 100644 --- a/src/share/shaca/entities/sbranch.js +++ b/src/share/shaca/entities/sbranch.ts @@ -1,22 +1,27 @@ "use strict"; -const AbstractShacaEntity = require('./abstract_shaca_entity'); +import AbstractShacaEntity = require('./abstract_shaca_entity'); +import SNote = require('./snote'); + +type BranchRow = [ string, string, string, string, string, boolean ]; class SBranch extends AbstractShacaEntity { - constructor([branchId, noteId, parentNoteId, prefix, isExpanded]) { + + private branchId: string; + private noteId: string; + private parentNoteId: string; + private prefix: string; + private isExpanded: boolean; + isHidden: boolean; + + constructor([branchId, noteId, parentNoteId, prefix, isExpanded]: BranchRow) { super(); - /** @param {string} */ this.branchId = branchId; - /** @param {string} */ this.noteId = noteId; - /** @param {string} */ this.parentNoteId = parentNoteId; - /** @param {string} */ this.prefix = prefix; - /** @param {boolean} */ this.isExpanded = !!isExpanded; - /** @param {boolean} */ this.isHidden = false; const childNote = this.childNote; @@ -38,25 +43,21 @@ class SBranch extends AbstractShacaEntity { this.shaca.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this; } - /** @returns {SNote} */ - get childNote() { + get childNote(): SNote { return this.shaca.notes[this.noteId]; } - /** @returns {SNote} */ getNote() { return this.childNote; } - /** @returns {SNote} */ - get parentNote() { + get parentNote(): SNote { return this.shaca.notes[this.parentNoteId]; } - /** @returns {SNote} */ getParentNote() { return this.parentNote; } } -module.exports = SBranch; +export = SBranch; diff --git a/src/share/shaca/entities/snote.ts b/src/share/shaca/entities/snote.ts index 9f8205865..5f924938d 100644 --- a/src/share/shaca/entities/snote.ts +++ b/src/share/shaca/entities/snote.ts @@ -7,6 +7,7 @@ import escape = require('escape-html'); import { Blob } from '../../../services/blob-interface'; import SAttachment = require('./sattachment'); import SAttribute = require('./sattribute'); +import SBranch = require('./sbranch'); const LABEL = 'label'; const RELATION = 'relation'; @@ -24,9 +25,9 @@ class SNote extends AbstractShacaEntity { private blobId: string; private utcDateModified: string; private isProtected: boolean; - private parentBranches: any[]; // fixme: set right data type once SBranch is ported. - private parents: SNote[]; - private children: SNote[]; + parentBranches: SBranch[]; + parents: SNote[]; + children: SNote[]; private ownedAttributes: SAttribute[]; private __attributeCache: SAttribute[] | null; private __inheritableAttributeCache: SAttribute[] | null; @@ -58,18 +59,15 @@ class SNote extends AbstractShacaEntity { this.shaca.notes[this.noteId] = this; } - /** @returns {SBranch[]} */ getParentBranches() { return this.parentBranches; } - /** @returns {SBranch[]} */ getBranches() { return this.parentBranches; } - /** @returns {SBranch[]} */ - getChildBranches() { + getChildBranches(): SBranch[] { return this.children.map(childNote => this.shaca.getBranchFromChildAndParent(childNote.noteId, this.noteId)); } diff --git a/src/share/shaca/shaca_loader.js b/src/share/shaca/shaca_loader.js index 9763c4718..6c7c802a5 100644 --- a/src/share/shaca/shaca_loader.js +++ b/src/share/shaca/shaca_loader.js @@ -4,7 +4,7 @@ const sql = require('../sql'); const shaca = require('./shaca.js'); const log = require('../../services/log'); const SNote = require('./entities/snote'); -const SBranch = require('./entities/sbranch.js'); +const SBranch = require('./entities/sbranch'); const SAttribute = require('./entities/sattribute'); const SAttachment = require('./entities/sattachment'); const shareRoot = require('../share_root');