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
becca conversion WIP
zadam3091119893a2
diff --git a/spec/search/note_cache_mocking.js b/spec/search/note_cache_mocking.jsindex 27afb59561..b3fc35c8aa 100644--- a/spec/search/note_cache_mocking.js+++ b/spec/search/note_cache_mocking.js@@ -66,7 +66,7 @@ function note(title, extraParams = {}) {mime: 'text/html'}, extraParams);- const note = new Note(becca, row);+ const note = new Note(row);return new NoteBuilder(note);}diff --git a/spec/search/search.spec.js b/spec/search/search.spec.jsindex 68a5a21719..3d46b61701 100644--- a/spec/search/search.spec.js+++ b/spec/search/search.spec.js@@ -12,7 +12,7 @@ describe("Search", () => {beforeEach(() => {becca.reset();- rootNote = new NoteBuilder(new Note(becca, {noteId: 'root', title: 'root', type: 'text'}));+ rootNote = new NoteBuilder(new Note({noteId: 'root', title: 'root', type: 'text'}));new Branch(becca, {branchId: 'root', noteId: 'root', parentNoteId: 'none', notePosition: 10});});diff --git a/src/entities/api_token.js b/src/entities/api_token.jsdeleted file mode 100644index cc643d99c1..0000000000--- a/src/entities/api_token.js+++ /dev/null@@ -1,34 +0,0 @@-"use strict";--const Entity = require('./entity');-const dateUtils = require('../services/date_utils');--/**- * ApiToken is an entity representing token used to authenticate against Trilium API from client applications. Currently used only by Trilium Sender.- *- * @property {string} apiTokenId - primary key- * @property {string} token- * @property {boolean} isDeleted - true if API token is deleted- * @property {string} utcDateCreated- *- * @extends Entity- */-class ApiToken extends Entity {- static get entityName() { return "api_tokens"; }- static get primaryKeyName() { return "apiTokenId"; }- static get hashedProperties() { return ["apiTokenId", "token", "utcDateCreated", "isDeleted"]; }-- beforeSaving() {- if (!this.isDeleted) {- this.isDeleted = false;- }-- if (!this.utcDateCreated) {- this.utcDateCreated = dateUtils.utcNowDateTime();- }-- super.beforeSaving();- }-}--module.exports = ApiToken;\ No newline at end of filediff --git a/src/entities/entity_constructor.js b/src/entities/entity_constructor.jsindex c51bc931c3..f02c27eaea 100644--- a/src/entities/entity_constructor.js+++ b/src/entities/entity_constructor.js@@ -4,7 +4,7 @@ const NoteRevision = require('../services/becca/entities/note_revision.js');const Branch = require('../entities/branch');const Attribute = require('../entities/attribute');const RecentNote = require('../services/becca/entities/recent_note.js');-const ApiToken = require('../entities/api_token');+const ApiToken = require('../services/becca/entities/api_token.js');const cls = require('../services/cls');const ENTITY_NAME_TO_ENTITY = {diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.jsindex 144174c510..2794cb26a2 100644--- a/src/routes/api/attributes.js+++ b/src/routes/api/attributes.js@@ -4,7 +4,7 @@ const sql = require('../../services/sql');const log = require('../../services/log');const attributeService = require('../../services/attributes');const repository = require('../../services/repository');-const Attribute = require('../../entities/attribute');+const Attribute = require('../../services/becca/entities/attribute');const becca = require("../../services/becca/becca");function getEffectiveNoteAttributes(req) {@@ -56,7 +56,6 @@ function updateNoteAttribute(req) {if (attribute.type === 'label' || body.value.trim()) {attribute.value = body.value;- attribute.isDeleted = false;}else {// relations should never have empty targetdiff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.jsindex eeef650348..1aea27a722 100644--- a/src/routes/api/clipper.js+++ b/src/routes/api/clipper.js@@ -10,7 +10,7 @@ const ws = require('../../services/ws.js');const log = require('../../services/log');const utils = require('../../services/utils');const path = require('path');-const Attribute = require('../../entities/attribute');+const Attribute = require('../../services/becca/entities/attribute');const htmlSanitizer = require('../../services/html_sanitizer');function findClippingNote(todayNote, pageUrl) {diff --git a/src/routes/api/login.js b/src/routes/api/login.jsindex 159e43be1a..382e831883 100644--- a/src/routes/api/login.js+++ b/src/routes/api/login.js@@ -12,7 +12,7 @@ const cls = require('../../services/cls');const sqlInit = require('../../services/sql_init');const sql = require('../../services/sql');const optionService = require('../../services/options');-const ApiToken = require('../../entities/api_token');+const ApiToken = require('../../services/becca/entities/api_token.js');function loginSync(req) {if (!sqlInit.schemaExists()) {diff --git a/src/services/attributes.js b/src/services/attributes.jsindex bcf256e26d..87d72c968b 100644--- a/src/services/attributes.js+++ b/src/services/attributes.js@@ -3,7 +3,7 @@const searchService = require('./search/services/search');const sql = require('./sql');const becca = require('./becca/becca.js');-const Attribute = require('../entities/attribute');+const Attribute = require('./becca/entities/attribute');const {formatAttrForSearch} = require("./attribute_formatter.js");const ATTRIBUTE_TYPES = [ 'label', 'relation' ];diff --git a/src/services/auth.js b/src/services/auth.jsindex b6ec61311e..74a1ec1ddb 100644--- a/src/services/auth.js+++ b/src/services/auth.js@@ -63,6 +63,7 @@ function checkAppNotInitialized(req, res, next) {function checkToken(req, res, next) {const token = req.headers.authorization;+ // TODO: put all tokens into becca memory to avoid these requestsif (sql.getValue("SELECT COUNT(*) FROM api_tokens WHERE isDeleted = 0 AND token = ?", [token]) === 0) {reject(req, res, "Token not found");}diff --git a/src/services/becca/entities/api_token.js b/src/services/becca/entities/api_token.jsnew file mode 100644index 0000000000..e44b31f28c--- /dev/null+++ b/src/services/becca/entities/api_token.js@@ -0,0 +1,23 @@+"use strict";++const dateUtils = require('../../date_utils.js');+const AbstractEntity = require("./abstract_entity.js");++/**+ * ApiToken is an entity representing token used to authenticate against Trilium API from client applications. Currently used only by Trilium Sender.+ */+class ApiToken extends AbstractEntity {+ static get entityName() { return "api_tokens"; }+ static get primaryKeyName() { return "apiTokenId"; }+ static get hashedProperties() { return ["apiTokenId", "token", "utcDateCreated"]; }++ constructor(row) {+ super();++ this.apiTokenId = row.apiTokenId;+ this.token = row.token;+ this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime();+ }+}++module.exports = ApiToken;diff --git a/src/services/becca/entities/attribute.js b/src/services/becca/entities/attribute.jsindex b581235a11..4cd65090c1 100644--- a/src/services/becca/entities/attribute.js+++ b/src/services/becca/entities/attribute.js@@ -33,7 +33,7 @@ class Attribute extends AbstractEntity {if (!(this.noteId in this.becca.notes)) {// entities can come out of order in sync, create skeleton which will be filled later- this.becca.notes[this.noteId] = new Note(this.becca, {noteId: this.noteId});+ this.becca.notes[this.noteId] = new Note({noteId: this.noteId});}this.becca.notes[this.noteId].ownedAttributes.push(this);diff --git a/src/services/becca/entities/branch.js b/src/services/becca/entities/branch.jsindex 5b1c9b3ea3..24895aa956 100644--- a/src/services/becca/entities/branch.js+++ b/src/services/becca/entities/branch.js@@ -47,7 +47,7 @@ class Branch extends AbstractEntity {get childNote() {if (!(this.noteId in this.becca.notes)) {// entities can come out of order in sync, create skeleton which will be filled later- this.becca.notes[this.noteId] = new Note(this.becca, {noteId: this.noteId});+ this.becca.notes[this.noteId] = new Note({noteId: this.noteId});}return this.becca.notes[this.noteId];@@ -61,7 +61,7 @@ class Branch extends AbstractEntity {get parentNote() {if (!(this.parentNoteId in this.becca.notes)) {// entities can come out of order in sync, create skeleton which will be filled later- this.becca.notes[this.parentNoteId] = new Note(this.becca, {noteId: this.parentNoteId});+ this.becca.notes[this.parentNoteId] = new Note({noteId: this.parentNoteId});}return this.becca.notes[this.parentNoteId];diff --git a/src/services/cloning.js b/src/services/cloning.jsindex 017f418c21..37d401891c 100644--- a/src/services/cloning.js+++ b/src/services/cloning.js@@ -5,7 +5,7 @@ const eventChangesService = require('./entity_changes.js');const treeService = require('./tree');const noteService = require('./notes');const repository = require('./repository');-const Branch = require('../entities/branch');+const Branch = require('../services/becca/entities/branch');const TaskContext = require("./task_context.js");const utils = require('./utils');const becca = require("./becca/becca");diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex 3b60f8d9b5..871d7ff7fd 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -9,7 +9,7 @@ const repository = require('./repository');const cls = require('./cls');const entityChangesService = require('./entity_changes.js');const optionsService = require('./options');-const Branch = require('../entities/branch');+const Branch = require('../services/becca/entities/branch');const dateUtils = require('./date_utils');const attributeService = require('./attributes');const noteRevisionService = require('./note_revisions');diff --git a/src/services/handlers.js b/src/services/handlers.jsindex e41b1b2a54..525ba87cf9 100644--- a/src/services/handlers.js+++ b/src/services/handlers.js@@ -2,9 +2,8 @@ const eventService = require('./events');const scriptService = require('./script');const treeService = require('./tree');const noteService = require('./notes');-const repository = require('./repository');const becca = require('./becca/becca.js');-const Attribute = require('../entities/attribute');+const Attribute = require('./becca/entities/attribute');function runAttachedRelations(note, relationName, originEntity) {// same script note can get here with multiple ways, but execute only oncediff --git a/src/services/import/zip.js b/src/services/import/zip.jsindex 38984f2b48..2ae54ce925 100644--- a/src/services/import/zip.js+++ b/src/services/import/zip.js@@ -1,12 +1,11 @@"use strict";-const Attribute = require('../../entities/attribute');+const Attribute = require('../../services/becca/entities/attribute');const utils = require('../../services/utils');const log = require('../../services/log');-const repository = require('../../services/repository');const noteService = require('../../services/notes');const attributeService = require('../../services/attributes');-const Branch = require('../../entities/branch');+const Branch = require('../../services/becca/entities/branch');const path = require('path');const commonmark = require('commonmark');const protectedSessionService = require('../protected_session');diff --git a/src/services/tree.js b/src/services/tree.jsindex a5f1be02b6..d22303fae7 100644--- a/src/services/tree.js+++ b/src/services/tree.js@@ -3,7 +3,7 @@const sql = require('./sql');const log = require('./log');const repository = require('./repository');-const Branch = require('../entities/branch');+const Branch = require('../services/becca/entities/branch');const entityChangesService = require('./entity_changes.js');const protectedSessionService = require('./protected_session');const becca = require('./becca/becca.js');