diff --git a/src/entities/attribute.js b/src/entities/attribute.js index 878ae04b7..fe6a2f44f 100644 --- a/src/entities/attribute.js +++ b/src/entities/attribute.js @@ -41,7 +41,7 @@ class Attribute extends Entity { * @returns {Note|null} */ getNote() { - return this.repository.getNote(this.noteId); + return this.becca.getNote(this.noteId); } /** @@ -56,7 +56,7 @@ class Attribute extends Entity { return null; } - return this.repository.getNote(this.value); + return this.becca.getNote(this.value); } /** diff --git a/src/entities/branch.js b/src/entities/branch.js index a46b75d17..61d48e32c 100644 --- a/src/entities/branch.js +++ b/src/entities/branch.js @@ -29,12 +29,12 @@ class Branch extends Entity { /** @returns {Note|null} */ getNote() { - return this.repository.getNote(this.noteId); + return this.becca.getNote(this.noteId); } /** @returns {Note|null} */ getParentNote() { - return this.repository.getNote(this.parentNoteId); + return this.becca.getNote(this.parentNoteId); } beforeSaving() { diff --git a/src/entities/note.js b/src/entities/note.js index fda454c05..f6a4951c5 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -658,7 +658,7 @@ class Note extends Entity { getRelationTarget(name) { const relation = this.getRelation(name); - return relation ? this.repository.getNote(relation.value) : null; + return relation ? this.becca.getNote(relation.value) : null; } /** @@ -668,7 +668,7 @@ class Note extends Entity { getOwnedRelationTarget(name) { const relation = this.getOwnedRelation(name); - return relation ? this.repository.getNote(relation.value) : null; + return relation ? this.becca.getNote(relation.value) : null; } /** diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index 7eeb7e669..242754fa9 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -8,7 +8,7 @@ const Attribute = require('../../entities/attribute'); const becca = require("../../services/becca/becca.js"); function getEffectiveNoteAttributes(req) { - const note = repository.getNote(req.params.noteId); + const note = becca.getNote(req.params.noteId); return note.getAttributes(); } @@ -19,7 +19,7 @@ function updateNoteAttribute(req) { let attribute; if (body.attributeId) { - attribute = repository.getAttribute(body.attributeId); + attribute = becca.getAttribute(body.attributeId); if (attribute.noteId !== noteId) { return [400, `Attribute ${body.attributeId} is not owned by ${noteId}`]; @@ -116,7 +116,7 @@ function updateNoteAttributes(req) { const noteId = req.params.noteId; const incomingAttributes = req.body; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); let existingAttrs = note.getOwnedAttributes(); @@ -143,7 +143,7 @@ function updateNoteAttributes(req) { } if (incAttr.type === 'relation') { - const targetNote = repository.getNote(incAttr.value); + const targetNote = becca.getNote(incAttr.value); if (!targetNote || targetNote.isDeleted) { log.error(`Target note of relation ${JSON.stringify(incAttr)} does not exist or is deleted`); diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index b83be175d..e95eb3062 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -17,8 +17,8 @@ const TaskContext = require('../../services/task_context'); function moveBranchToParent(req) { const {branchId, parentBranchId} = req.params; - const parentBranch = repository.getBranch(parentBranchId); - const branchToMove = repository.getBranch(branchId); + const parentBranch = becca.getBranch(parentBranchId); + const branchToMove = becca.getBranch(branchId); if (!parentBranch || !branchToMove) { return [400, `One or both branches ${branchId}, ${parentBranchId} have not been found`]; @@ -53,8 +53,8 @@ function moveBranchToParent(req) { function moveBranchBeforeNote(req) { const {branchId, beforeBranchId} = req.params; - const branchToMove = repository.getBranch(branchId); - const beforeBranch = repository.getBranch(beforeBranchId); + const branchToMove = becca.getBranch(branchId); + const beforeBranch = becca.getBranch(beforeBranchId); if (!branchToMove) { return [404, `Can't find branch ${branchId}`]; @@ -95,8 +95,8 @@ function moveBranchBeforeNote(req) { function moveBranchAfterNote(req) { const {branchId, afterBranchId} = req.params; - const branchToMove = repository.getBranch(branchId); - const afterNote = repository.getBranch(afterBranchId); + const branchToMove = becca.getBranch(branchId); + const afterNote = becca.getBranch(afterBranchId); const validationResult = treeService.validateParentChild(afterNote.parentNoteId, branchToMove.noteId, branchId); @@ -180,7 +180,7 @@ function setExpandedForSubtree(req) { function deleteBranch(req) { const last = req.query.last === 'true'; - const branch = repository.getBranch(req.params.branchId); + const branch = becca.getBranch(req.params.branchId); const taskContext = TaskContext.getInstance(req.query.taskId, 'delete-notes'); const deleteId = utils.randomString(10); @@ -199,7 +199,7 @@ function setPrefix(req) { const branchId = req.params.branchId; const prefix = utils.isEmptyOrWhitespace(req.body.prefix) ? null : req.body.prefix; - const branch = repository.getBranch(branchId); + const branch = becca.getBranch(branchId); branch.prefix = prefix; branch.save(); } diff --git a/src/routes/api/date_notes.js b/src/routes/api/date_notes.js index b28ad3aa7..311f04c26 100644 --- a/src/routes/api/date_notes.js +++ b/src/routes/api/date_notes.js @@ -130,7 +130,7 @@ function createSearchNote(req) { function getHoistedNote() { return cls.getHoistedNoteId() && cls.getHoistedNoteId() !== 'root' - ? repository.getNote(cls.getHoistedNoteId()) + ? becca.getNote(cls.getHoistedNoteId()) : null; } diff --git a/src/routes/api/export.js b/src/routes/api/export.js index de905d0cd..e4c81db52 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -9,7 +9,7 @@ const log = require("../../services/log"); function exportBranch(req, res) { const {branchId, type, format, version, taskId} = req.params; - const branch = repository.getBranch(branchId); + const branch = becca.getBranch(branchId); if (!branch) { const message = `Cannot export branch ${branchId} since it does not exist.`; diff --git a/src/routes/api/files.js b/src/routes/api/files.js index 2a9f90e83..b85bcee7f 100644 --- a/src/routes/api/files.js +++ b/src/routes/api/files.js @@ -1,7 +1,6 @@ "use strict"; const protectedSessionService = require('../../services/protected_session'); -const repository = require('../../services/repository'); const utils = require('../../services/utils'); const log = require('../../services/log'); const noteRevisionService = require('../../services/note_revisions'); @@ -10,12 +9,13 @@ const fs = require('fs'); const { Readable } = require('stream'); const chokidar = require('chokidar'); const ws = require('../../services/ws'); +const becca = require("../../services/becca/becca.js"); function updateFile(req) { const {noteId} = req.params; const file = req.file; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note) { return [404, `Note ${noteId} doesn't exist.`]; @@ -44,7 +44,7 @@ function getFilename(note) { } function downloadNoteFile(noteId, res, contentDisposition = true) { - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note) { return res.status(404).send(`Note ${noteId} doesn't exist.`); @@ -79,7 +79,7 @@ function openFile(req, res) { function fileContentProvider(req) { // Read file name from route params. - const note = repository.getNote(req.params.noteId); + const note = becca.getNote(req.params.noteId); const fileName = getFilename(note); let content = note.getContent(); @@ -112,7 +112,7 @@ function fileContentProvider(req) { function saveToTmpDir(req) { const noteId = req.params.noteId; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note) { return [404,`Note ${noteId} doesn't exist.`]; diff --git a/src/routes/api/image.js b/src/routes/api/image.js index 9e509ad37..d36788bf4 100644 --- a/src/routes/api/image.js +++ b/src/routes/api/image.js @@ -6,7 +6,7 @@ const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR; const fs = require('fs'); function returnImage(req, res) { - const image = repository.getNote(req.params.noteId); + const image = becca.getNote(req.params.noteId); if (!image) { return res.sendStatus(404); @@ -28,7 +28,7 @@ function uploadImage(req) { const {noteId} = req.query; const {file} = req; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note) { return [404, `Note ${noteId} doesn't exist.`]; @@ -50,7 +50,7 @@ function updateImage(req) { const {noteId} = req.params; const {file} = req; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note) { return [404, `Note ${noteId} doesn't exist.`]; diff --git a/src/routes/api/import.js b/src/routes/api/import.js index b02054b5c..619ef4f07 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -30,7 +30,7 @@ async function importToBranch(req) { return [400, "No file has been uploaded"]; } - const parentNote = repository.getNote(parentNoteId); + const parentNote = becca.getNote(parentNoteId); if (!parentNote) { return [404, `Note ${parentNoteId} doesn't exist.`]; diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 6a0178a30..8457cfd68 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -13,7 +13,7 @@ const becca = require("../../services/becca/becca.js"); function getNote(req) { const noteId = req.params.noteId; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note) { return [404, "Note " + noteId + " has not been found."]; @@ -67,7 +67,7 @@ function deleteNote(req) { // note how deleteId is separate from taskId - single taskId produces separate deleteId for each "top level" deleted note const deleteId = utils.randomString(10); - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); const taskContext = TaskContext.getInstance(taskId, 'delete-notes'); @@ -81,7 +81,7 @@ function deleteNote(req) { } function undeleteNote(req) { - const note = repository.getNote(req.params.noteId); + const note = becca.getNote(req.params.noteId); const taskContext = TaskContext.getInstance(utils.randomString(10), 'undeleteNotes'); @@ -125,7 +125,7 @@ function setNoteTypeMime(req) { const type = req.params[1]; const mime = req.params[2]; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); note.type = type; note.mime = mime; note.save(); @@ -150,7 +150,7 @@ function getRelationMap(req) { const questionMarks = noteIds.map(noteId => '?').join(','); - const relationMapNote = repository.getNote(relationMapNoteId); + const relationMapNote = becca.getNote(relationMapNoteId); const displayRelationsVal = relationMapNote.getLabelValue('displayRelations'); const displayRelations = !displayRelationsVal ? [] : displayRelationsVal @@ -191,7 +191,7 @@ function changeTitle(req) { const noteId = req.params.noteId; const title = req.body.title; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note) { return [404, `Note ${noteId} has not been found`]; @@ -246,7 +246,7 @@ function getDeleteNotesPreview(req) { } for (const branchId of branchIdsToDelete) { - const branch = repository.getBranch(branchId); + const branch = becca.getBranch(branchId); if (!branch) { log.error(`Branch ${branchId} was not found and delete preview can't be calculated for this note.`); @@ -280,7 +280,7 @@ function uploadModifiedFile(req) { const noteId = req.params.noteId; const {filePath} = req.body; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note) { return [404, `Note ${noteId} has not been found`]; diff --git a/src/routes/api/script.js b/src/routes/api/script.js index bcc0ac936..343169496 100644 --- a/src/routes/api/script.js +++ b/src/routes/api/script.js @@ -30,7 +30,7 @@ async function exec(req) { } async function run(req) { - const note = repository.getNote(req.params.noteId); + const note = becca.getNote(req.params.noteId); const result = await scriptService.executeNote(note, { originEntity: note }); @@ -78,7 +78,7 @@ function getWidgetBundles() { function getRelationBundles(req) { const noteId = req.params.noteId; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); const relationName = req.params.relationName; const attributes = note.getAttributes(); @@ -89,7 +89,7 @@ function getRelationBundles(req) { const bundles = []; for (const noteId of uniqueNoteIds) { - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note.isJavaScript() || note.getScriptEnv() !== 'frontend') { continue; @@ -106,7 +106,7 @@ function getRelationBundles(req) { } function getBundle(req) { - const note = repository.getNote(req.params.noteId); + const note = becca.getNote(req.params.noteId); return scriptService.getScriptBundleForFrontend(note); } diff --git a/src/routes/api/search.js b/src/routes/api/search.js index a3b90b2e2..6d13b218d 100644 --- a/src/routes/api/search.js +++ b/src/routes/api/search.js @@ -38,7 +38,7 @@ async function searchFromNoteInt(note) { } async function searchFromNote(req) { - const note = repository.getNote(req.params.noteId); + const note = becca.getNote(req.params.noteId); if (!note) { return [404, `Note ${req.params.noteId} has not been found.`]; @@ -130,7 +130,7 @@ function getActions(note) { } async function searchAndExecute(req) { - const note = repository.getNote(req.params.noteId); + const note = becca.getNote(req.params.noteId); if (!note) { return [404, `Note ${req.params.noteId} has not been found.`]; @@ -150,7 +150,7 @@ async function searchAndExecute(req) { const actions = getActions(note); for (const resultNoteId of searchResultNoteIds) { - const resultNote = repository.getNote(resultNoteId); + const resultNote = becca.getNote(resultNoteId); if (!resultNote || resultNote.isDeleted) { continue; diff --git a/src/routes/api/similar_notes.js b/src/routes/api/similar_notes.js index 79417004f..35f81328d 100644 --- a/src/routes/api/similar_notes.js +++ b/src/routes/api/similar_notes.js @@ -1,12 +1,12 @@ "use strict"; const similarityService = require('../../services/becca/similarity.js'); -const repository = require('../../services/repository'); +const becca = require("../../services/becca/becca.js"); async function getSimilarNotes(req) { const noteId = req.params.noteId; - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note) { return [404, `Note ${noteId} not found.`]; diff --git a/src/routes/api/sql.js b/src/routes/api/sql.js index 990de9969..a50f5829b 100644 --- a/src/routes/api/sql.js +++ b/src/routes/api/sql.js @@ -18,7 +18,7 @@ function getSchema() { } function execute(req) { - const note = repository.getNote(req.params.noteId); + const note = becca.getNote(req.params.noteId); if (!note) { return [404, `Note ${req.params.noteId} was not found.`]; diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 6df8afcc9..5a751d852 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -275,7 +275,7 @@ function BackendScriptApi(currentNote, apiParams) { extraOptions.parentNoteId = parentNoteId; extraOptions.title = title; - const parentNote = repository.getNote(parentNoteId); + const parentNote = becca.getNote(parentNoteId); // code note type can be inherited, otherwise text is default extraOptions.type = parentNote.type === 'code' ? 'code' : 'text'; diff --git a/src/services/cloning.js b/src/services/cloning.js index 35742a77b..8fd26dcf8 100644 --- a/src/services/cloning.js +++ b/src/services/cloning.js @@ -8,9 +8,10 @@ const repository = require('./repository'); const Branch = require('../entities/branch'); const TaskContext = require("./task_context.js"); const utils = require('./utils'); +const becca = require("./becca/becca.js"); function cloneNoteToParent(noteId, parentBranchId, prefix) { - const parentBranch = repository.getBranch(parentBranchId); + const parentBranch = becca.getBranch(parentBranchId); if (isNoteDeleted(noteId) || isNoteDeleted(parentBranch.noteId)) { return { success: false, message: 'Note is deleted.' }; @@ -73,7 +74,7 @@ function toggleNoteInParent(present, noteId, parentNoteId, prefix) { } function cloneNoteAfter(noteId, afterBranchId) { - const afterNote = repository.getBranch(afterBranchId); + const afterNote = becca.getBranch(afterBranchId); if (isNoteDeleted(noteId) || isNoteDeleted(afterNote.parentNoteId)) { return { success: false, message: 'Note is deleted.' }; @@ -103,7 +104,7 @@ function cloneNoteAfter(noteId, afterBranchId) { } function isNoteDeleted(noteId) { - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); return note.isDeleted; } diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 697b22ee2..6ba24f967 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -13,6 +13,7 @@ const Branch = require('../entities/branch'); const dateUtils = require('./date_utils'); const attributeService = require('./attributes'); const noteRevisionService = require('./note_revisions'); +const becca = require("./becca/becca.js"); class ConsistencyChecks { constructor(autoFix) { @@ -101,7 +102,7 @@ class ConsistencyChecks { AND notes.noteId IS NULL`, ({branchId, noteId}) => { if (this.autoFix) { - const branch = repository.getBranch(branchId); + const branch = becca.getBranch(branchId); branch.isDeleted = true; branch.save(); @@ -120,7 +121,7 @@ class ConsistencyChecks { AND notes.noteId IS NULL`, ({branchId, parentNoteId}) => { if (this.autoFix) { - const branch = repository.getBranch(branchId); + const branch = becca.getBranch(branchId); branch.parentNoteId = 'root'; branch.save(); @@ -138,7 +139,7 @@ class ConsistencyChecks { AND notes.noteId IS NULL`, ({attributeId, noteId}) => { if (this.autoFix) { - const attribute = repository.getAttribute(attributeId); + const attribute = becca.getAttribute(attributeId); attribute.isDeleted = true; attribute.save(); @@ -157,7 +158,7 @@ class ConsistencyChecks { AND notes.noteId IS NULL`, ({attributeId, noteId}) => { if (this.autoFix) { - const attribute = repository.getAttribute(attributeId); + const attribute = becca.getAttribute(attributeId); attribute.isDeleted = true; attribute.save(); @@ -183,7 +184,7 @@ class ConsistencyChecks { AND branches.isDeleted = 0`, ({branchId, noteId}) => { if (this.autoFix) { - const branch = repository.getBranch(branchId); + const branch = becca.getBranch(branchId); branch.isDeleted = true; branch.save(); @@ -202,7 +203,7 @@ class ConsistencyChecks { AND branches.isDeleted = 0 `, ({branchId, parentNoteId}) => { if (this.autoFix) { - const branch = repository.getBranch(branchId); + const branch = becca.getBranch(branchId); branch.isDeleted = true; branch.save(); @@ -274,7 +275,7 @@ class ConsistencyChecks { AND type NOT IN ('text', 'code', 'render', 'file', 'image', 'search', 'relation-map', 'book')`, ({noteId, type}) => { if (this.autoFix) { - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); note.type = 'file'; // file is a safe option to recover notes if type is not known note.save(); @@ -291,7 +292,7 @@ class ConsistencyChecks { WHERE note_contents.noteId IS NULL`, ({noteId}) => { if (this.autoFix) { - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (note.isProtected) { // this is wrong for non-erased notes but we cannot set a valid value for protected notes @@ -323,7 +324,7 @@ class ConsistencyChecks { AND content IS NULL`, ({noteId}) => { if (this.autoFix) { - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); // empty string might be wrong choice for some note types but it's a best guess note.setContent(''); @@ -382,7 +383,7 @@ class ConsistencyChecks { AND value = ''`, ({attributeId}) => { if (this.autoFix) { - const relation = repository.getAttribute(attributeId); + const relation = becca.getAttribute(attributeId); relation.isDeleted = true; relation.save(); @@ -401,7 +402,7 @@ class ConsistencyChecks { AND type != 'relation'`, ({attributeId, type}) => { if (this.autoFix) { - const attribute = repository.getAttribute(attributeId); + const attribute = becca.getAttribute(attributeId); attribute.type = 'label'; attribute.save(); @@ -420,7 +421,7 @@ class ConsistencyChecks { AND notes.isDeleted = 1`, ({attributeId, noteId}) => { if (this.autoFix) { - const attribute = repository.getAttribute(attributeId); + const attribute = becca.getAttribute(attributeId); attribute.isDeleted = true; attribute.save(); @@ -440,7 +441,7 @@ class ConsistencyChecks { AND notes.isDeleted = 1`, ({attributeId, targetNoteId}) => { if (this.autoFix) { - const attribute = repository.getAttribute(attributeId); + const attribute = becca.getAttribute(attributeId); attribute.isDeleted = true; attribute.save(); diff --git a/src/services/export/opml.js b/src/services/export/opml.js index 143b12ace..f5060d9ef 100644 --- a/src/services/export/opml.js +++ b/src/services/export/opml.js @@ -2,6 +2,7 @@ const repository = require("../repository"); const utils = require('../utils'); +const becca = require("../becca/becca.js"); function exportToOpml(taskContext, branch, version, res) { if (!['1.0', '2.0'].includes(version)) { @@ -13,7 +14,7 @@ function exportToOpml(taskContext, branch, version, res) { const note = branch.getNote(); function exportNoteInner(branchId) { - const branch = repository.getBranch(branchId); + const branch = becca.getBranch(branchId); const note = branch.getNote(); if (note.hasOwnedLabel('excludeFromExport')) { diff --git a/src/services/export/zip.js b/src/services/export/zip.js index bc44ba7b0..fad0a0eca 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -273,7 +273,7 @@ ${content} return; } - const note = repository.getNote(noteMeta.noteId); + const note = becca.getNote(noteMeta.noteId); notePaths[note.noteId] = filePathPrefix + (noteMeta.dataFileName || noteMeta.dirFileName); diff --git a/src/services/handlers.js b/src/services/handlers.js index 073b65d72..829d89d8d 100644 --- a/src/services/handlers.js +++ b/src/services/handlers.js @@ -51,9 +51,9 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) => runAttachedRelations(entity.getNote(), 'runOnAttributeCreation', entity); if (entity.type === 'relation' && entity.name === 'template') { - const note = repository.getNote(entity.noteId); + const note = becca.getNote(entity.noteId); - const templateNote = repository.getNote(entity.value); + const templateNote = becca.getNote(entity.value); if (!templateNote) { return; diff --git a/src/services/image.js b/src/services/image.js index 9334f9b6c..4d2338e22 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -55,7 +55,7 @@ function getImageMimeFromExtension(ext) { function updateImage(noteId, uploadBuffer, originalName) { log.info(`Updating image ${noteId}: ${originalName}`); - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); noteRevisionService.createNoteRevision(note); noteRevisionService.protectNoteRevisions(note); @@ -78,7 +78,7 @@ function saveImage(parentNoteId, uploadBuffer, originalName, shrinkImageSwitch) const fileName = sanitizeFilename(originalName); - const parentNote = repository.getNote(parentNoteId); + const parentNote = becca.getNote(parentNoteId); const {note} = noteService.createNewNote({ parentNoteId, diff --git a/src/services/import/zip.js b/src/services/import/zip.js index 3361b6b2a..38984f2b4 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -171,7 +171,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) { const noteTitle = utils.getNoteTitle(filePath, taskContext.data.replaceUnderscoresWithSpaces, noteMeta); const parentNoteId = getParentNoteId(filePath, parentNoteMeta); - let note = repository.getNote(noteId); + let note = becca.getNote(noteId); if (note) { return; @@ -340,7 +340,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) { } } - let note = repository.getNote(noteId); + let note = becca.getNote(noteId); if (note) { note.setContent(content); @@ -458,7 +458,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) { }); for (const noteId in createdNoteIds) { // now the noteIds are unique - noteService.scanForLinks(repository.getNote(noteId)); + noteService.scanForLinks(becca.getNote(noteId)); if (!metaFile) { // if there's no meta file then the notes are created based on the order in that tar file but that diff --git a/src/services/notes.js b/src/services/notes.js index 03f79c6b0..657165526 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -320,7 +320,7 @@ function downloadImages(noteId, content) { && (url.length !== 20 || url.toLowerCase().startsWith('http'))) { if (url in imageUrlToNoteIdMapping) { - const imageNote = repository.getNote(imageUrlToNoteIdMapping[url]); + const imageNote = becca.getNote(imageUrlToNoteIdMapping[url]); if (!imageNote || imageNote.isDeleted) { delete imageUrlToNoteIdMapping[url]; @@ -363,9 +363,9 @@ function downloadImages(noteId, content) { // which upon the download of all the images will update the note if the links have not been fixed before sql.transactional(() => { - const imageNotes = repository.getNotes(Object.values(imageUrlToNoteIdMapping)); + const imageNotes = becca.getNotes(Object.values(imageUrlToNoteIdMapping)); - const origNote = repository.getNote(noteId); + const origNote = becca.getNote(noteId); const origContent = origNote.getContent(); let updatedContent = origContent; @@ -477,7 +477,7 @@ function saveNoteRevision(note) { } function updateNote(noteId, noteUpdates) { - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (!note.isContentAvailable) { throw new Error(`Note ${noteId} is not available for change!`); @@ -784,7 +784,7 @@ function duplicateSubtreeWithoutRoot(origNoteId, newNoteId) { throw new Error('Duplicating root is not possible'); } - const origNote = repository.getNote(origNoteId); + const origNote = becca.getNote(origNoteId); const noteIdMapping = getNoteIdMapping(origNote); for (const childBranch of origNote.getChildBranches()) { diff --git a/src/services/repository.js b/src/services/repository.js index 045e4b51a..bf260defa 100644 --- a/src/services/repository.js +++ b/src/services/repository.js @@ -155,10 +155,5 @@ module.exports = { getEntities, getEntity, getNote, - getNotes, - getNoteRevision, - getBranch, - getAttribute, - getOption, updateEntity }; diff --git a/src/services/script.js b/src/services/script.js index 9f495f20c..e8d2f2ad0 100644 --- a/src/services/script.js +++ b/src/services/script.js @@ -52,8 +52,8 @@ async function executeBundle(bundle, apiParams = {}) { * bundle's startNote. */ async function executeScript(script, params, startNoteId, currentNoteId, originEntityName, originEntityId) { - const startNote = repository.getNote(startNoteId); - const currentNote = repository.getNote(currentNoteId); + const startNote = becca.getNote(startNoteId); + const currentNote = becca.getNote(currentNoteId); const originEntity = repository.getEntityFromName(originEntityName, originEntityId); currentNote.content = `return (${script}\r\n)(${getParams(params)})`; diff --git a/src/services/setup.js b/src/services/setup.js index 04969abb4..becd97257 100644 --- a/src/services/setup.js +++ b/src/services/setup.js @@ -7,6 +7,7 @@ const syncOptions = require('./sync_options'); const request = require('./request'); const appInfo = require('./app_info'); const utils = require('./utils'); +const becca = require("./becca/becca.js"); async function hasSyncServerSchemaAndSeed() { const response = await requestToSyncServer('GET', '/api/setup/status'); @@ -107,8 +108,8 @@ async function setupSyncFromSyncServer(syncServerHost, syncProxy, username, pass function getSyncSeedOptions() { return [ - repository.getOption('documentId'), - repository.getOption('documentSecret') + becca.getOption('documentId'), + becca.getOption('documentSecret') ]; } diff --git a/src/services/tree.js b/src/services/tree.js index 723e3887d..a0cecf7f7 100644 --- a/src/services/tree.js +++ b/src/services/tree.js @@ -156,7 +156,7 @@ function sortNotesByTitle(parentNoteId, foldersFirst = false, reverse = false) { function sortNotes(parentNoteId, sortBy, reverse = false) { sql.transactional(() => { - const notes = repository.getNote(parentNoteId).getChildNotes(); + const notes = becca.getNote(parentNoteId).getChildNotes(); notes.sort((a, b) => a[sortBy] < b[sortBy] ? -1 : 1); @@ -185,7 +185,7 @@ function sortNotes(parentNoteId, sortBy, reverse = false) { * @deprecated - this will be removed in the future */ function setNoteToParent(noteId, prefix, parentNoteId) { - const parentNote = repository.getNote(parentNoteId); + const parentNote = becca.getNote(parentNoteId); if (parentNote && parentNote.isDeleted) { throw new Error(`Cannot move note to deleted parent note ${parentNoteId}`); @@ -206,7 +206,7 @@ function setNoteToParent(noteId, prefix, parentNoteId) { branch.save(); } else if (parentNoteId) { - const note = repository.getNote(noteId); + const note = becca.getNote(noteId); if (note.isDeleted) { throw new Error(`Cannot create a branch for ${noteId} which is deleted.`); diff --git a/src/tools/generate_document.js b/src/tools/generate_document.js index 4d5f7b11e..67a6c8936 100644 --- a/src/tools/generate_document.js +++ b/src/tools/generate_document.js @@ -84,7 +84,7 @@ async function start() { isInheritable: Math.random() > 0.1 // 10% are inheritable }); - noteRevisionService.createNoteRevision(await repository.getNote(getRandomNoteId())); + noteRevisionService.createNoteRevision(await becca.getNote(getRandomNoteId())); notes.push(note.noteId); } @@ -92,4 +92,4 @@ async function start() { process.exit(0); } -sqlInit.dbReady.then(cls.wrap(start)); \ No newline at end of file +sqlInit.dbReady.then(cls.wrap(start));