Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
server-ts: Port bbranch (with some build errors)
Elian Doranf51f070b2fa0
diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.tsindex 041e4b0cc7..f71a81822b 100644--- a/src/becca/becca-interface.ts+++ b/src/becca/becca-interface.ts@@ -5,6 +5,7 @@ import BOption = require('./entities/boption');import BNote = require('./entities/bnote');import BEtapiToken = require('./entities/betapi_token');import BAttribute = require('./entities/battribute');+import BBranch = require('./entities/bbranch');/*** Becca is a backend cache of all notes, branches, and attributes.@@ -14,6 +15,8 @@ class Becca {loaded!: boolean;notes!: Record<string, BNote>;+ branches!: Record<string, BBranch>;+ childParentToBranch!: Record<string, BBranch>;attributes!: Record<string, BAttribute>;/** Points from attribute type-name to list of attributes */attributeIndex!: Record<string, BAttribute[]>;@@ -25,11 +28,8 @@ class Becca {}reset() {- /** @type {Object.<String, BNote>} */this.notes = {};- /** @type {Object.<String, BBranch>} */this.branches = {};- /** @type {Object.<String, BBranch>} */this.childParentToBranch = {};this.attributes = {};this.attributeIndex = {};diff --git a/src/becca/entities/bbranch.js b/src/becca/entities/bbranch.tssimilarity index 89%rename from src/becca/entities/bbranch.jsrename to src/becca/entities/bbranch.tsindex b9a04af7fc..f7ed4cffc0 100644--- a/src/becca/entities/bbranch.js+++ b/src/becca/entities/bbranch.ts@@ -1,12 +1,13 @@"use strict";-const BNote = require('./bnote.js');-const AbstractBeccaEntity = require('./abstract_becca_entity.js');-const dateUtils = require('../../services/date_utils');-const utils = require('../../services/utils');-const TaskContext = require('../../services/task_context.js');-const cls = require('../../services/cls');-const log = require('../../services/log');+import BNote = require('./bnote.js');+import AbstractBeccaEntity = require('./abstract_becca_entity.js');+import dateUtils = require('../../services/date_utils');+import utils = require('../../services/utils');+import TaskContext = require('../../services/task_context');+import cls = require('../../services/cls');+import log = require('../../services/log');+import { BranchRow } from './rows.js';/*** Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple@@ -23,7 +24,15 @@ class BBranch extends AbstractBeccaEntity {// notePosition is not part of hash because it would produce a lot of updates in case of reorderingstatic get hashedProperties() { return ["branchId", "noteId", "parentNoteId", "prefix"]; }- constructor(row) {+ branchId?: string;+ noteId!: string;+ parentNoteId!: string;+ prefix!: string;+ notePosition!: number;+ isExpanded!: boolean;+ utcDateModified?: string;++ constructor(row: BranchRow) {super();if (!row) {@@ -34,7 +43,7 @@ class BBranch extends AbstractBeccaEntity {this.init();}- updateFromRow(row) {+ updateFromRow(row: BranchRow) {this.update([row.branchId,row.noteId,@@ -46,20 +55,13 @@ class BBranch extends AbstractBeccaEntity {]);}- update([branchId, noteId, parentNoteId, prefix, notePosition, isExpanded, utcDateModified]) {- /** @type {string} */+ update([branchId, noteId, parentNoteId, prefix, notePosition, isExpanded, utcDateModified]: any) {this.branchId = branchId;- /** @type {string} */this.noteId = noteId;- /** @type {string} */this.parentNoteId = parentNoteId;- /** @type {string|null} */this.prefix = prefix;- /** @type {int} */this.notePosition = notePosition;- /** @type {boolean} */this.isExpanded = !!isExpanded;- /** @type {string} */this.utcDateModified = utcDateModified;return this;@@ -138,12 +140,11 @@ class BBranch extends AbstractBeccaEntity {/*** Delete a branch. If this is a last note's branch, delete the note as well.*- * @param {string} [deleteId] - optional delete identified- * @param {TaskContext} [taskContext]+ * @param deleteId - optional delete identified*- * @returns {boolean} - true if note has been deleted, false otherwise+ * @returns true if note has been deleted, false otherwise*/- deleteBranch(deleteId, taskContext) {+ deleteBranch(deleteId: string, taskContext: TaskContext): boolean {if (!deleteId) {deleteId = utils.randomString(10);}@@ -261,7 +262,7 @@ class BBranch extends AbstractBeccaEntity {};}- createClone(parentNoteId, notePosition) {+ createClone(parentNoteId: string, notePosition: number) {const existingBranch = this.becca.getBranchFromChildAndParent(this.noteId, parentNoteId);if (existingBranch) {@@ -279,4 +280,4 @@ class BBranch extends AbstractBeccaEntity {}}-module.exports = BBranch;+export = BBranch;diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.tsindex 98bb0ec8a8..db51542e0c 100644--- a/src/becca/entities/rows.ts+++ b/src/becca/entities/rows.ts@@ -72,4 +72,14 @@ export interface AttributeRow {value: string;isInheritable: boolean;utcDateModified: string;+}++export interface BranchRow {+ branchId?: string;+ noteId: string;+ parentNoteId: string;+ prefix: string | null;+ notePosition: number;+ isExpanded: boolean;+ utcDateModified?: string;}\ No newline at end of filediff --git a/src/services/task_context.js b/src/services/task_context.tssimilarity index 72%rename from src/services/task_context.jsrename to src/services/task_context.tsindex 58530ffece..2b1272bb5c 100644--- a/src/services/task_context.js+++ b/src/services/task_context.ts@@ -1,12 +1,20 @@"use strict";-const ws = require('./ws.js');+import ws = require('./ws.js');// taskId => TaskContext-const taskContexts = {};+const taskContexts: Record<string, TaskContext> = {};class TaskContext {- constructor(taskId, taskType = null, data = {}) {++ private taskId: string;+ private taskType: string | null;+ private data: {} | null;+ private noteDeletionHandlerTriggered: boolean;+ private progressCount: number;+ private lastSentCountTs: number;++ constructor(taskId: string, taskType: string | null = null, data: {} | null = {}) {this.taskId = taskId;this.taskType = taskType;this.data = data;@@ -23,8 +31,7 @@ class TaskContext {this.increaseProgressCount();}- /** @returns {TaskContext} */- static getInstance(taskId, taskType, data = null) {+ static getInstance(taskId: string, taskType: string, data: {} | null = null): TaskContext {if (!taskContexts[taskId]) {taskContexts[taskId] = new TaskContext(taskId, taskType, data);}@@ -42,31 +49,31 @@ class TaskContext {type: 'taskProgressCount',taskId: this.taskId,taskType: this.taskType,- data: this.data,+ data: this.data || undefined,progressCount: this.progressCount});}}- reportError(message) {+ reportError(message: string) {ws.sendMessageToAllClients({type: 'taskError',taskId: this.taskId,taskType: this.taskType,- data: this.data,+ data: this.data || undefined,message: message});}- taskSucceeded(result) {+ taskSucceeded(result: string) {ws.sendMessageToAllClients({type: 'taskSucceeded',taskId: this.taskId,taskType: this.taskType,- data: this.data,+ data: this.data || undefined,result: result});}}-module.exports = TaskContext;+export = TaskContext;diff --git a/src/services/ws.ts b/src/services/ws.tsindex 9e76868e4f..086bb0d4f9 100644--- a/src/services/ws.ts+++ b/src/services/ws.ts@@ -28,12 +28,18 @@ let lastSyncedPush: number | null = null;interface Message {type: string;- reason?: string;data?: {lastSyncedPush?: number,entityChanges?: any[]},- lastSyncedPush?: number+ lastSyncedPush?: number,++ progressCount?: number;+ taskId?: string;+ taskType?: string | null;+ message?: string;+ reason?: string;+ result?: string;}type SessionParser = (req: IncomingMessage, params: {}, cb: () => void) => void;@@ -252,7 +258,7 @@ function setLastSyncedPush(entityChangeId: number) {lastSyncedPush = entityChangeId;}-module.exports = {+export = {init,sendMessageToAllClients,syncPushInProgress,