mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
becca conversion WIP
This commit is contained in:
parent
d13c8771ca
commit
1af10d48a2
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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`);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ function createSearchNote(req) {
|
||||
|
||||
function getHoistedNote() {
|
||||
return cls.getHoistedNoteId() && cls.getHoistedNoteId() !== 'root'
|
||||
? repository.getNote(cls.getHoistedNoteId())
|
||||
? becca.getNote(cls.getHoistedNoteId())
|
||||
: null;
|
||||
}
|
||||
|
||||
|
@ -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.`;
|
||||
|
@ -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.`];
|
||||
|
@ -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.`];
|
||||
|
@ -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.`];
|
||||
|
@ -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`];
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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.`];
|
||||
|
@ -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.`];
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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')) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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()) {
|
||||
|
@ -155,10 +155,5 @@ module.exports = {
|
||||
getEntities,
|
||||
getEntity,
|
||||
getNote,
|
||||
getNotes,
|
||||
getNoteRevision,
|
||||
getBranch,
|
||||
getAttribute,
|
||||
getOption,
|
||||
updateEntity
|
||||
};
|
||||
|
@ -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)})`;
|
||||
|
@ -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')
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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.`);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user