Skip to content

Build your personal knowledge base with Trilium Notes

server-ts: Port becca/becca_service

Elian Doran9f99b4282a90
diff --git a/src/becca/becca_service.js b/src/becca/becca_service.ts
similarity index 82%
rename from src/becca/becca_service.js
rename to src/becca/becca_service.ts
index 15a1c07cc9..2a9eb27812 100644
--- a/src/becca/becca_service.js
+++ b/src/becca/becca_service.ts
@@ -1,10 +1,10 @@
"use strict";
-const becca = require('./becca');
-const cls = require('../services/cls');
-const log = require('../services/log');
+import becca = require('./becca');
+import cls = require('../services/cls');
+import log = require('../services/log');
-function isNotePathArchived(notePath) {
+function isNotePathArchived(notePath: string[]) {
const noteId = notePath[notePath.length - 1];
const note = becca.notes[noteId];
@@ -24,9 +24,9 @@ function isNotePathArchived(notePath) {
return false;
}
-function getNoteTitle(childNoteId, parentNoteId) {
+function getNoteTitle(childNoteId: string, parentNoteId?: string) {
const childNote = becca.notes[childNoteId];
- const parentNote = becca.notes[parentNoteId];
+ const parentNote = parentNoteId ? becca.notes[parentNoteId] : null;
if (!childNote) {
log.info(`Cannot find note '${childNoteId}'`);
@@ -40,7 +40,7 @@ function getNoteTitle(childNoteId, parentNoteId) {
return `${(branch && branch.prefix) ? `${branch.prefix} - ` : ''}${title}`;
}
-function getNoteTitleArrayForPath(notePathArray) {
+function getNoteTitleArrayForPath(notePathArray: string[]) {
if (!notePathArray || !Array.isArray(notePathArray)) {
throw new Error(`${notePathArray} is not an array.`);
}
@@ -76,13 +76,13 @@ function getNoteTitleArrayForPath(notePathArray) {
return titles;
}
-function getNoteTitleForPath(notePathArray) {
+function getNoteTitleForPath(notePathArray: string[]) {
const titles = getNoteTitleArrayForPath(notePathArray);
return titles.join(' / ');
}
-module.exports = {
+export = {
getNoteTitle,
getNoteTitleForPath,
isNotePathArchived
diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.js
index a3113ba628..4d48709a0c 100644
--- a/src/routes/api/autocomplete.js
+++ b/src/routes/api/autocomplete.js
@@ -1,6 +1,6 @@
"use strict";
-const beccaService = require('../../becca/becca_service.js');
+const beccaService = require('../../becca/becca_service');
const searchService = require('../../services/search/services/search.js');
const log = require('../../services/log');
const utils = require('../../services/utils');
diff --git a/src/routes/api/revisions.js b/src/routes/api/revisions.js
index 33f6fc1442..f553b18bcc 100644
--- a/src/routes/api/revisions.js
+++ b/src/routes/api/revisions.js
@@ -1,6 +1,6 @@
"use strict";
-const beccaService = require('../../becca/becca_service.js');
+const beccaService = require('../../becca/becca_service');
const revisionService = require('../../services/revisions');
const utils = require('../../services/utils');
const sql = require('../../services/sql');
diff --git a/src/services/search/expressions/note_flat_text.js b/src/services/search/expressions/note_flat_text.js
index e9fc2fad82..cf523bfbbf 100644
--- a/src/services/search/expressions/note_flat_text.js
+++ b/src/services/search/expressions/note_flat_text.js
@@ -14,7 +14,7 @@ class NoteFlatTextExp extends Expression {
execute(inputNoteSet, executionContext, searchContext) {
// has deps on SQL which breaks unit test so needs to be dynamically required
- const beccaService = require('../../../becca/becca_service.js');
+ const beccaService = require('../../../becca/becca_service');
const resultNoteSet = new NoteSet();
/**
diff --git a/src/services/search/search_result.js b/src/services/search/search_result.js
index 61f7d86d81..ca3811f8ec 100644
--- a/src/services/search/search_result.js
+++ b/src/services/search/search_result.js
@@ -1,6 +1,6 @@
"use strict";
-const beccaService = require('../../becca/becca_service.js');
+const beccaService = require('../../becca/becca_service');
const becca = require('../../becca/becca');
class SearchResult {
diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js
index 498d31310a..828c624a81 100644
--- a/src/services/search/services/search.js
+++ b/src/services/search/services/search.js
@@ -7,7 +7,7 @@ const parse = require('./parse.js');
const SearchResult = require('../search_result.js');
const SearchContext = require('../search_context.js');
const becca = require('../../../becca/becca');
-const beccaService = require('../../../becca/becca_service.js');
+const beccaService = require('../../../becca/becca_service');
const utils = require('../../utils');
const log = require('../../log');
const hoistedNoteService = require('../../hoisted_note.js');