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 services/branches
Elian Doran9ea4fcd66788
diff --git a/src/routes/api/branches.js b/src/routes/api/branches.jsindex c313f5aa3b..4638fb63e3 100644--- a/src/routes/api/branches.js+++ b/src/routes/api/branches.js@@ -7,7 +7,7 @@ const treeService = require('../../services/tree');const eraseService = require('../../services/erase');const becca = require('../../becca/becca');const TaskContext = require('../../services/task_context');-const branchService = require('../../services/branches.js');+const branchService = require('../../services/branches');const log = require('../../services/log');const ValidationError = require('../../errors/validation_error');const eventService = require("../../services/events");diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.jsindex f7fcac10ad..ff3e16be52 100644--- a/src/services/backend_script_api.js+++ b/src/services/backend_script_api.js@@ -17,7 +17,7 @@ const becca = require('../becca/becca');const ws = require('./ws');const SpacedUpdate = require('./spaced_update.js');const specialNotesService = require('./special_notes.js');-const branchService = require('./branches.js');+const branchService = require('./branches');const exportService = require('./export/zip.js');const syncMutex = require('./sync_mutex');const backupService = require('./backup');diff --git a/src/services/branches.js b/src/services/branches.tssimilarity index 61%rename from src/services/branches.jsrename to src/services/branches.tsindex 7fab98cd1a..7ee32c9498 100644--- a/src/services/branches.js+++ b/src/services/branches.ts@@ -1,7 +1,8 @@-const treeService = require('./tree');-const sql = require('./sql');+import treeService = require('./tree');+import sql = require('./sql');+import BBranch = require('../becca/entities/bbranch.js');-function moveBranchToNote(branchToMove, targetParentNoteId) {+function moveBranchToNote(branchToMove: BBranch, targetParentNoteId: string) {if (branchToMove.parentNoteId === targetParentNoteId) {return {success: true}; // no-op}@@ -12,8 +13,8 @@ function moveBranchToNote(branchToMove, targetParentNoteId) {return [200, validationResult];}- const maxNotePos = sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [targetParentNoteId]);- const newNotePos = maxNotePos === null ? 0 : maxNotePos + 10;+ const maxNotePos = sql.getValue<number | null>('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [targetParentNoteId]);+ const newNotePos = !maxNotePos ? 0 : maxNotePos + 10;const newBranch = branchToMove.createClone(targetParentNoteId, newNotePos);newBranch.save();@@ -26,10 +27,10 @@ function moveBranchToNote(branchToMove, targetParentNoteId) {};}-function moveBranchToBranch(branchToMove, targetParentBranch) {+function moveBranchToBranch(branchToMove: BBranch, targetParentBranch: BBranch) {const res = moveBranchToNote(branchToMove, targetParentBranch.noteId);- if (!res.success) {+ if (!("success" in res) || !res.success) {return res;}@@ -42,7 +43,7 @@ function moveBranchToBranch(branchToMove, targetParentBranch) {return res;}-module.exports = {+export = {moveBranchToBranch,moveBranchToNote};diff --git a/src/services/bulk_actions.js b/src/services/bulk_actions.jsindex 136d1cccfc..d894f21882 100644--- a/src/services/bulk_actions.js+++ b/src/services/bulk_actions.js@@ -2,7 +2,7 @@ const log = require('./log');const revisionService = require('./revisions');const becca = require('../becca/becca');const cloningService = require('./cloning.js');-const branchService = require('./branches.js');+const branchService = require('./branches');const utils = require('./utils');const eraseService = require("./erase");diff --git a/src/services/tree.ts b/src/services/tree.tsindex 56291b6206..d731fe6b0c 100644--- a/src/services/tree.ts+++ b/src/services/tree.ts@@ -261,7 +261,7 @@ function setNoteToParent(noteId: string, prefix: string, parentNoteId: string) {}}-module.exports = {+export = {validateParentChild,sortNotes,sortNotesIfNeeded,