mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	becca conversion WIP
This commit is contained in:
		| @@ -75,24 +75,6 @@ function BackendScriptApi(currentNote, apiParams) { | |||||||
|      */ |      */ | ||||||
|     this.getAttribute = becca.getAttribute; |     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.: |      * 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/Search |      * "#dateModified =* MONTH AND #log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search | ||||||
|   | |||||||
| @@ -79,6 +79,21 @@ class Becca { | |||||||
|     getOption(name) { |     getOption(name) { | ||||||
|         return this.options[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(); | const becca = new Becca(); | ||||||
|   | |||||||
| @@ -6,16 +6,6 @@ const eventService = require('./events'); | |||||||
| const cls = require('./cls'); | const cls = require('./cls'); | ||||||
| const entityConstructor = require('../entities/entity_constructor'); | 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 = []) { | function getEntities(query, params = []) { | ||||||
|     const rows = sql.getRows(query, params); |     const rows = sql.getRows(query, params); | ||||||
|  |  | ||||||
| @@ -151,9 +141,6 @@ function updateEntity(entity) { | |||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     getEntityFromName, |  | ||||||
|     getEntities, |     getEntities, | ||||||
|     getEntity, |  | ||||||
|     getNote, |  | ||||||
|     updateEntity |     updateEntity | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ const ScriptContext = require('./script_context'); | |||||||
| const repository = require('./repository'); | const repository = require('./repository'); | ||||||
| const cls = require('./cls'); | const cls = require('./cls'); | ||||||
| const log = require('./log'); | const log = require('./log'); | ||||||
|  | const becca = require("./becca/becca.js"); | ||||||
|  |  | ||||||
| async function executeNote(note, apiParams) { | async function executeNote(note, apiParams) { | ||||||
|     if (!note.isJavaScript() || note.getScriptEnv() !== 'backend' || !note.isContentAvailable) { |     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) { | async function executeScript(script, params, startNoteId, currentNoteId, originEntityName, originEntityId) { | ||||||
|     const startNote = becca.getNote(startNoteId); |     const startNote = becca.getNote(startNoteId); | ||||||
|     const currentNote = becca.getNote(currentNoteId); |     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.content = `return (${script}\r\n)(${getParams(params)})`; | ||||||
|     currentNote.type = 'code'; |     currentNote.type = 'code'; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user