From 9f99b4282a9074e2112beb585a1395bd9d16bd5b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 20:30:21 +0200 Subject: [PATCH] server-ts: Port becca/becca_service --- .../{becca_service.js => becca_service.ts} | 18 +++++++++--------- src/routes/api/autocomplete.js | 2 +- src/routes/api/revisions.js | 2 +- .../search/expressions/note_flat_text.js | 2 +- src/services/search/search_result.js | 2 +- src/services/search/services/search.js | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) rename src/becca/{becca_service.js => becca_service.ts} (82%) 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 15a1c07cc..2a9eb2781 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 a3113ba62..4d48709a0 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 33f6fc144..f553b18bc 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 e9fc2fad8..cf523bfbb 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 61f7d86d8..ca3811f8e 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 498d31310..828c624a8 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');