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
zadam77eac8f76487
diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.jsindex 5a751d852d..a824940d22 100644--- a/src/services/backend_script_api.js+++ b/src/services/backend_script_api.js@@ -75,24 +75,6 @@ function BackendScriptApi(currentNote, apiParams) {*/this.getAttribute = becca.getAttribute;- /**- * Retrieves first entity from the SQL's result set.- *- * @method- * @param {string} SQL query- * @param {Array.<?>} array of params- * @returns {Entity|null}- */- this.getEntity = repository.getEntity;-- /**- * @method- * @param {string} SQL query- * @param {Array.<?>} array of params- * @returns {Entity[]}- */- this.getEntities = repository.getEntities;-/*** This is a powerful search method - you can search by attributes and their values, e.g.:* "#dateModified =* MONTH AND #log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Searchdiff --git a/src/services/becca/becca.js b/src/services/becca/becca.jsindex f2a2ad7e1e..74f16b5264 100644--- a/src/services/becca/becca.js+++ b/src/services/becca/becca.js@@ -79,6 +79,21 @@ class Becca {getOption(name) {return this.options[name];}++ getEntityFromName(entityName, entityId) {+ if (!entityName || !entityId) {+ return null;+ }++ const camelCaseEntityName = entityName.toLowerCase().replace(/(_[a-z])/g,+ group =>+ group+ .toUpperCase()+ .replace('_', '')+ );++ return this[camelCaseEntityName][entityId];+ }}const becca = new Becca();diff --git a/src/services/repository.js b/src/services/repository.jsindex bf260defa2..84e3b04016 100644--- a/src/services/repository.js+++ b/src/services/repository.js@@ -6,16 +6,6 @@ const eventService = require('./events');const cls = require('./cls');const entityConstructor = require('../entities/entity_constructor');-function getEntityFromName(entityName, entityId) {- if (!entityName || !entityId) {- return null;- }-- const constructor = entityConstructor.getEntityFromEntityName(entityName);-- return getEntity(`SELECT * FROM ${constructor.entityName} WHERE ${constructor.primaryKeyName} = ?`, [entityId]);-}-function getEntities(query, params = []) {const rows = sql.getRows(query, params);@@ -151,9 +141,6 @@ function updateEntity(entity) {}module.exports = {- getEntityFromName,getEntities,- getEntity,- getNote,updateEntity};diff --git a/src/services/script.js b/src/services/script.jsindex e8d2f2ad04..ee27c536c4 100644--- a/src/services/script.js+++ b/src/services/script.js@@ -2,6 +2,7 @@ const ScriptContext = require('./script_context');const repository = require('./repository');const cls = require('./cls');const log = require('./log');+const becca = require("./becca/becca.js");async function executeNote(note, apiParams) {if (!note.isJavaScript() || note.getScriptEnv() !== 'backend' || !note.isContentAvailable) {@@ -54,7 +55,7 @@ async function executeBundle(bundle, apiParams = {}) {async function executeScript(script, params, startNoteId, currentNoteId, originEntityName, originEntityId) {const startNote = becca.getNote(startNoteId);const currentNote = becca.getNote(currentNoteId);- const originEntity = repository.getEntityFromName(originEntityName, originEntityId);+ const originEntity = becca.getEntityFromName(originEntityName, originEntityId);currentNote.content = `return (${script}\r\n)(${getParams(params)})`;currentNote.type = 'code';