server-ts: Port share/shaca/sbranch

This commit is contained in:
Elian Doran 2024-04-09 22:32:06 +03:00
parent e1d74cd2f5
commit 0865e90cae
No known key found for this signature in database
3 changed files with 22 additions and 23 deletions

View File

@ -1,22 +1,27 @@
"use strict"; "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 { 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(); super();
/** @param {string} */
this.branchId = branchId; this.branchId = branchId;
/** @param {string} */
this.noteId = noteId; this.noteId = noteId;
/** @param {string} */
this.parentNoteId = parentNoteId; this.parentNoteId = parentNoteId;
/** @param {string} */
this.prefix = prefix; this.prefix = prefix;
/** @param {boolean} */
this.isExpanded = !!isExpanded; this.isExpanded = !!isExpanded;
/** @param {boolean} */
this.isHidden = false; this.isHidden = false;
const childNote = this.childNote; const childNote = this.childNote;
@ -38,25 +43,21 @@ class SBranch extends AbstractShacaEntity {
this.shaca.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this; this.shaca.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this;
} }
/** @returns {SNote} */ get childNote(): SNote {
get childNote() {
return this.shaca.notes[this.noteId]; return this.shaca.notes[this.noteId];
} }
/** @returns {SNote} */
getNote() { getNote() {
return this.childNote; return this.childNote;
} }
/** @returns {SNote} */ get parentNote(): SNote {
get parentNote() {
return this.shaca.notes[this.parentNoteId]; return this.shaca.notes[this.parentNoteId];
} }
/** @returns {SNote} */
getParentNote() { getParentNote() {
return this.parentNote; return this.parentNote;
} }
} }
module.exports = SBranch; export = SBranch;

View File

@ -7,6 +7,7 @@ import escape = require('escape-html');
import { Blob } from '../../../services/blob-interface'; import { Blob } from '../../../services/blob-interface';
import SAttachment = require('./sattachment'); import SAttachment = require('./sattachment');
import SAttribute = require('./sattribute'); import SAttribute = require('./sattribute');
import SBranch = require('./sbranch');
const LABEL = 'label'; const LABEL = 'label';
const RELATION = 'relation'; const RELATION = 'relation';
@ -24,9 +25,9 @@ class SNote extends AbstractShacaEntity {
private blobId: string; private blobId: string;
private utcDateModified: string; private utcDateModified: string;
private isProtected: boolean; private isProtected: boolean;
private parentBranches: any[]; // fixme: set right data type once SBranch is ported. parentBranches: SBranch[];
private parents: SNote[]; parents: SNote[];
private children: SNote[]; children: SNote[];
private ownedAttributes: SAttribute[]; private ownedAttributes: SAttribute[];
private __attributeCache: SAttribute[] | null; private __attributeCache: SAttribute[] | null;
private __inheritableAttributeCache: SAttribute[] | null; private __inheritableAttributeCache: SAttribute[] | null;
@ -58,18 +59,15 @@ class SNote extends AbstractShacaEntity {
this.shaca.notes[this.noteId] = this; this.shaca.notes[this.noteId] = this;
} }
/** @returns {SBranch[]} */
getParentBranches() { getParentBranches() {
return this.parentBranches; return this.parentBranches;
} }
/** @returns {SBranch[]} */
getBranches() { getBranches() {
return this.parentBranches; return this.parentBranches;
} }
/** @returns {SBranch[]} */ getChildBranches(): SBranch[] {
getChildBranches() {
return this.children.map(childNote => this.shaca.getBranchFromChildAndParent(childNote.noteId, this.noteId)); return this.children.map(childNote => this.shaca.getBranchFromChildAndParent(childNote.noteId, this.noteId));
} }

View File

@ -4,7 +4,7 @@ const sql = require('../sql');
const shaca = require('./shaca.js'); const shaca = require('./shaca.js');
const log = require('../../services/log'); const log = require('../../services/log');
const SNote = require('./entities/snote'); const SNote = require('./entities/snote');
const SBranch = require('./entities/sbranch.js'); const SBranch = require('./entities/sbranch');
const SAttribute = require('./entities/sattribute'); const SAttribute = require('./entities/sattribute');
const SAttachment = require('./entities/sattachment'); const SAttachment = require('./entities/sattachment');
const shareRoot = require('../share_root'); const shareRoot = require('../share_root');