| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | const log = require('./log'); | 
					
						
							|  |  |  | const noteService = require('./notes'); | 
					
						
							|  |  |  | const sql = require('./sql'); | 
					
						
							|  |  |  | const utils = require('./utils'); | 
					
						
							|  |  |  | const attributeService = require('./attributes'); | 
					
						
							|  |  |  | const dateNoteService = require('./date_notes'); | 
					
						
							|  |  |  | const treeService = require('./tree'); | 
					
						
							|  |  |  | const config = require('./config'); | 
					
						
							|  |  |  | const axios = require('axios'); | 
					
						
							| 
									
										
										
										
											2019-03-14 20:49:10 +01:00
										 |  |  | const dayjs = require('dayjs'); | 
					
						
							| 
									
										
										
										
											2021-04-05 11:18:56 +02:00
										 |  |  | const xml2js = require('xml2js'); | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | const cloningService = require('./cloning'); | 
					
						
							| 
									
										
										
										
											2019-01-18 23:57:08 +01:00
										 |  |  | const appInfo = require('./app_info'); | 
					
						
							| 
									
										
										
										
											2020-09-07 22:11:16 +02:00
										 |  |  | const searchService = require('./search/services/search'); | 
					
						
							| 
									
										
										
										
											2021-06-29 22:15:57 +02:00
										 |  |  | const SearchContext = require("./search/search_context"); | 
					
						
							|  |  |  | const becca = require("../becca/becca"); | 
					
						
							| 
									
										
										
										
											2022-09-17 23:06:17 +02:00
										 |  |  | const ws = require("./ws"); | 
					
						
							|  |  |  | const SpacedUpdate = require("./spaced_update"); | 
					
						
							| 
									
										
										
										
											2022-12-22 14:57:00 +01:00
										 |  |  | const specialNotesService = require("./special_notes"); | 
					
						
							| 
									
										
										
										
											2022-12-29 21:15:34 +01:00
										 |  |  | const branchService = require("./branches"); | 
					
						
							|  |  |  | const exportService = require("./export/zip"); | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-08-23 15:33:19 +02:00
										 |  |  |  * This is the main backend API interface for scripts. It's published in the local "api" object. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |  * @constructor | 
					
						
							|  |  |  |  * @hideconstructor | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-01-27 12:28:20 +01:00
										 |  |  | function BackendScriptApi(currentNote, apiParams) { | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |     /** @property {BNote} note where script started executing */ | 
					
						
							| 
									
										
										
										
											2019-01-27 12:28:20 +01:00
										 |  |  |     this.startNote = apiParams.startNote; | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |     /** @property {BNote} note where script is currently executing. Don't mix this up with concept of active note */ | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     this.currentNote = currentNote; | 
					
						
							| 
									
										
										
										
											2018-08-23 12:55:45 +02:00
										 |  |  |     /** @property {Entity} entity whose event triggered this executions */ | 
					
						
							| 
									
										
										
										
											2019-01-27 12:28:20 +01:00
										 |  |  |     this.originEntity = apiParams.originEntity; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (const key in apiParams) { | 
					
						
							|  |  |  |         this[key] = apiParams[key]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 22:01:52 +02:00
										 |  |  |     /** @property {axios} Axios library for HTTP requests. See https://axios-http.com/ for documentation */ | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     this.axios = axios; | 
					
						
							| 
									
										
										
										
											2021-04-07 22:01:52 +02:00
										 |  |  |     /** @property {dayjs} day.js library for date manipulation. See https://day.js.org/ for documentation */ | 
					
						
							| 
									
										
										
										
											2019-03-14 20:49:10 +01:00
										 |  |  |     this.dayjs = dayjs; | 
					
						
							| 
									
										
										
										
											2021-04-07 22:01:52 +02:00
										 |  |  |     /** @property {axios} xml2js library for XML parsing. See https://github.com/Leonidas-from-XIV/node-xml2js for documentation */ | 
					
						
							| 
									
										
										
										
											2021-04-05 11:18:56 +02:00
										 |  |  |     this.xml2js = xml2js; | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 22:01:52 +02:00
										 |  |  |     // DEPRECATED - use direct api.unescapeHtml
 | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     this.utils = { | 
					
						
							| 
									
										
										
										
											2019-03-14 20:49:10 +01:00
										 |  |  |         unescapeHtml: utils.unescapeHtml | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Instance name identifies particular Trilium instance. It can be useful for scripts | 
					
						
							|  |  |  |      * if some action needs to happen on only one specific instance. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @returns {string|null} | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     this.getInstanceName = () => config.General ? config.General.instanceName : null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} noteId | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-10-14 21:19:03 +02:00
										 |  |  |     this.getNote = noteId => becca.getNote(noteId); | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} branchId | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  |      * @returns {BBranch|null} | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-10-14 21:19:03 +02:00
										 |  |  |     this.getBranch = branchId => becca.getBranch(branchId); | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} attributeId | 
					
						
							| 
									
										
										
										
											2020-07-01 23:50:33 +02:00
										 |  |  |      * @returns {Attribute|null} | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-10-14 21:19:03 +02:00
										 |  |  |     this.getAttribute = attributeId => becca.getAttribute(attributeId); | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-20 22:51:13 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This is a powerful search method - you can search by attributes and their values, e.g.: | 
					
						
							| 
									
										
										
										
											2020-09-04 22:54:50 +02:00
										 |  |  |      * "#dateModified =* MONTH AND #log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
 | 
					
						
							| 
									
										
										
										
											2019-03-20 22:51:13 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							| 
									
										
										
										
											2020-09-07 22:11:16 +02:00
										 |  |  |      * @param {string} query | 
					
						
							| 
									
										
										
										
											2021-02-09 22:32:25 +01:00
										 |  |  |      * @param {Object} [searchParams] | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @returns {BNote[]} | 
					
						
							| 
									
										
										
										
											2019-03-20 22:51:13 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-02-09 22:32:25 +01:00
										 |  |  |     this.searchForNotes = (query, searchParams = {}) => { | 
					
						
							|  |  |  |         if (searchParams.includeArchivedNotes === undefined) { | 
					
						
							|  |  |  |             searchParams.includeArchivedNotes = true; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-07 22:11:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 21:56:46 +02:00
										 |  |  |         if (searchParams.ignoreHoistedNote === undefined) { | 
					
						
							|  |  |  |             searchParams.ignoreHoistedNote = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-17 20:52:46 +02:00
										 |  |  |         const noteIds = searchService.findResultsWithQuery(query, new SearchContext(searchParams)) | 
					
						
							| 
									
										
										
										
											2020-09-07 22:11:16 +02:00
										 |  |  |             .map(sr => sr.noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-26 22:24:55 +02:00
										 |  |  |         return becca.getNotes(noteIds); | 
					
						
							| 
									
										
										
										
											2020-09-07 22:11:16 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2019-03-20 22:51:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 18:08:33 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This is a powerful search method - you can search by attributes and their values, e.g.: | 
					
						
							| 
									
										
										
										
											2020-09-04 22:54:50 +02:00
										 |  |  |      * "#dateModified =* MONTH AND #log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
 | 
					
						
							| 
									
										
										
										
											2019-04-22 18:08:33 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							| 
									
										
										
										
											2021-04-26 22:27:12 +02:00
										 |  |  |      * @param {string} query | 
					
						
							|  |  |  |      * @param {Object} [searchParams] | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2019-04-22 18:08:33 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-04-26 22:27:12 +02:00
										 |  |  |     this.searchForNote = (query, searchParams = {}) => { | 
					
						
							|  |  |  |         const notes = this.searchForNotes(query, searchParams); | 
					
						
							| 
									
										
										
										
											2019-04-22 18:08:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return notes.length > 0 ? notes[0] : null; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Retrieves notes with given label name & value | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} name - attribute name | 
					
						
							|  |  |  |      * @param {string} [value] - attribute value | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @returns {BNote[]} | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.getNotesWithLabel = attributeService.getNotesWithLabel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Retrieves first note with given label name & value | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} name - attribute name | 
					
						
							|  |  |  |      * @param {string} [value] - attribute value | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.getNoteWithLabel = attributeService.getNoteWithLabel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2022-01-04 23:00:59 +01:00
										 |  |  |      * If there's no branch between note and parent note, create one. Otherwise, do nothing. | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} noteId | 
					
						
							|  |  |  |      * @param {string} parentNoteId | 
					
						
							| 
									
										
										
										
											2022-01-04 23:00:59 +01:00
										 |  |  |      * @param {string} prefix - if branch will be created between note and parent note, set this prefix | 
					
						
							| 
									
										
										
										
											2020-07-01 23:50:33 +02:00
										 |  |  |      * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2022-01-04 23:00:59 +01:00
										 |  |  |      * If there's a branch between note and parent note, remove it. Otherwise, do nothing. | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} noteId | 
					
						
							|  |  |  |      * @param {string} parentNoteId | 
					
						
							| 
									
										
										
										
											2020-07-01 23:50:33 +02:00
										 |  |  |      * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.ensureNoteIsAbsentFromParent = cloningService.ensureNoteIsAbsentFromParent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Based on the value, either create or remove branch between note and parent note. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {boolean} present - true if we want the branch to exist, false if we want it gone | 
					
						
							|  |  |  |      * @param {string} noteId | 
					
						
							|  |  |  |      * @param {string} parentNoteId | 
					
						
							| 
									
										
										
										
											2022-01-04 22:10:35 +01:00
										 |  |  |      * @param {string} prefix - if branch will be created between note and parent note, set this prefix | 
					
						
							| 
									
										
										
										
											2020-07-01 23:50:33 +02:00
										 |  |  |      * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.toggleNoteInParent = cloningService.toggleNoteInParent; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-25 21:24:41 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-11-28 22:35:55 +01:00
										 |  |  |      * Create text note. See also createNewNote() for more options. | 
					
						
							| 
									
										
										
										
											2019-11-25 21:24:41 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param {string} parentNoteId | 
					
						
							|  |  |  |      * @param {string} title | 
					
						
							|  |  |  |      * @param {string} content | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  |      * @return {{note: BNote, branch: BBranch}} - object having "note" and "branch" keys representing respective objects | 
					
						
							| 
									
										
										
										
											2019-11-25 21:24:41 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  |     this.createTextNote = (parentNoteId, title, content = '') => noteService.createNewNote({ | 
					
						
							| 
									
										
										
										
											2019-11-25 21:24:41 +01:00
										 |  |  |         parentNoteId, | 
					
						
							|  |  |  |         title, | 
					
						
							|  |  |  |         content, | 
					
						
							|  |  |  |         type: 'text' | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Create data note - data in this context means object serializable to JSON. Created note will be of type 'code' and | 
					
						
							| 
									
										
										
										
											2019-11-28 22:35:55 +01:00
										 |  |  |      * JSON MIME type. See also createNewNote() for more options. | 
					
						
							| 
									
										
										
										
											2019-11-25 21:24:41 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param {string} parentNoteId | 
					
						
							|  |  |  |      * @param {string} title | 
					
						
							|  |  |  |      * @param {object} content | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  |      * @return {{note: BNote, branch: BBranch}} object having "note" and "branch" keys representing respective objects | 
					
						
							| 
									
										
										
										
											2019-11-25 21:24:41 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  |     this.createDataNote = (parentNoteId, title, content = {}) => noteService.createNewNote({ | 
					
						
							| 
									
										
										
										
											2019-11-25 21:24:41 +01:00
										 |  |  |         parentNoteId, | 
					
						
							|  |  |  |         title, | 
					
						
							| 
									
										
										
										
											2020-01-04 18:44:54 +01:00
										 |  |  |         content: JSON.stringify(content, null, '\t'), | 
					
						
							| 
									
										
										
										
											2019-11-25 21:24:41 +01:00
										 |  |  |         type: 'code', | 
					
						
							|  |  |  |         mime: 'application/json' | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  |      * @property {object} params | 
					
						
							|  |  |  |      * @property {string} params.parentNoteId | 
					
						
							|  |  |  |      * @property {string} params.title | 
					
						
							|  |  |  |      * @property {string|buffer} params.content | 
					
						
							|  |  |  |      * @property {string} params.type - text, code, file, image, search, book, relationMap, canvas | 
					
						
							|  |  |  |      * @property {string} [params.mime] - value is derived from default mimes for type | 
					
						
							|  |  |  |      * @property {boolean} [params.isProtected=false] | 
					
						
							|  |  |  |      * @property {boolean} [params.isExpanded=false] | 
					
						
							|  |  |  |      * @property {string} [params.prefix=''] | 
					
						
							|  |  |  |      * @property {int} [params.notePosition] - default is last existing notePosition in a parent + 10 | 
					
						
							|  |  |  |      * @returns {{note: BNote, branch: BBranch}} object contains newly created entities note and branch | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-11-28 22:35:55 +01:00
										 |  |  |     this.createNewNote = noteService.createNewNote; | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 21:31:46 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @method | 
					
						
							| 
									
										
										
										
											2020-09-30 22:48:30 +02:00
										 |  |  |      * @deprecated please use createTextNote() with similar API for simpler use cases or createNewNote() for more complex needs | 
					
						
							| 
									
										
										
										
											2019-12-03 21:31:46 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param {string} parentNoteId - create new note under this parent | 
					
						
							|  |  |  |      * @param {string} title | 
					
						
							|  |  |  |      * @param {string} [content=""] | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  |      * @param {object} [extraOptions={}] | 
					
						
							|  |  |  |      * @property {boolean} [extraOptions.json=false] - should the note be JSON | 
					
						
							|  |  |  |      * @property {boolean} [extraOptions.isProtected=false] - should the note be protected | 
					
						
							|  |  |  |      * @property {string} [extraOptions.type='text'] - note type | 
					
						
							|  |  |  |      * @property {string} [extraOptions.mime='text/html'] - MIME type of the note | 
					
						
							|  |  |  |      * @property {object[]} [extraOptions.attributes=[]] - attributes to be created for this note | 
					
						
							|  |  |  |      * @property {string} extraOptions.attributes.type - attribute type - label, relation etc. | 
					
						
							|  |  |  |      * @property {string} extraOptions.attributes.name - attribute name | 
					
						
							|  |  |  |      * @property {string} [extraOptions.attributes.value] - attribute value | 
					
						
							|  |  |  |      * @returns {{note: BNote, branch: BBranch}} object contains newly created entities note and branch | 
					
						
							| 
									
										
										
										
											2019-12-03 21:31:46 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-06-20 12:31:38 +02:00
										 |  |  |     this.createNote = (parentNoteId, title, content = "", extraOptions= {}) => { | 
					
						
							| 
									
										
										
										
											2019-12-03 21:31:46 +01:00
										 |  |  |         extraOptions.parentNoteId = parentNoteId; | 
					
						
							|  |  |  |         extraOptions.title = title; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 11:23:58 +02:00
										 |  |  |         const parentNote = becca.getNote(parentNoteId); | 
					
						
							| 
									
										
										
										
											2019-12-03 21:31:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // code note type can be inherited, otherwise text is default
 | 
					
						
							|  |  |  |         extraOptions.type = parentNote.type === 'code' ? 'code' : 'text'; | 
					
						
							|  |  |  |         extraOptions.mime = parentNote.type === 'code' ? parentNote.mime : 'text/html'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (extraOptions.json) { | 
					
						
							|  |  |  |             extraOptions.content = JSON.stringify(content || {}, null, '\t'); | 
					
						
							|  |  |  |             extraOptions.type = 'code'; | 
					
						
							|  |  |  |             extraOptions.mime = 'application/json'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             extraOptions.content = content; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-30 22:45:15 +02:00
										 |  |  |         return sql.transactional(() => { | 
					
						
							| 
									
										
										
										
											2020-08-18 21:32:45 +02:00
										 |  |  |             const {note, branch} = noteService.createNewNote(extraOptions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (const attr of extraOptions.attributes || []) { | 
					
						
							|  |  |  |                 attributeService.createAttribute({ | 
					
						
							|  |  |  |                     noteId: note.noteId, | 
					
						
							|  |  |  |                     type: attr.type, | 
					
						
							|  |  |  |                     name: attr.name, | 
					
						
							|  |  |  |                     value: attr.value, | 
					
						
							|  |  |  |                     isInheritable: !!attr.isInheritable | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return {note, branch}; | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2019-12-03 21:31:46 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-17 23:06:17 +02:00
										 |  |  |     this.logMessages = {}; | 
					
						
							|  |  |  |     this.logSpacedUpdates = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2022-09-17 23:06:17 +02:00
										 |  |  |      * Log given message to trilium logs and log pane in UI | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param message | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-09-17 23:06:17 +02:00
										 |  |  |     this.log = message => { | 
					
						
							|  |  |  |         log.info(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const {noteId} = this.startNote; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.logMessages[noteId] = this.logMessages[noteId] || []; | 
					
						
							|  |  |  |         this.logSpacedUpdates[noteId] = this.logSpacedUpdates[noteId] || new SpacedUpdate(() => { | 
					
						
							|  |  |  |             const messages = this.logMessages[noteId]; | 
					
						
							|  |  |  |             this.logMessages[noteId] = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ws.sendMessageToAllClients({ | 
					
						
							|  |  |  |                 type: 'api-log-messages', | 
					
						
							|  |  |  |                 noteId, | 
					
						
							|  |  |  |                 messages | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         }, 100); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.logMessages[noteId].push(message); | 
					
						
							|  |  |  |         this.logSpacedUpdates[noteId].scheduleUpdate(); | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Returns root note of the calendar. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.getRootCalendarNote = dateNoteService.getRootCalendarNote; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-02-19 21:29:41 +01:00
										 |  |  |      * Returns day note for given date. If such note doesn't exist, it is created. | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							| 
									
										
										
										
											2019-02-19 21:29:41 +01:00
										 |  |  |      * @param {string} date in YYYY-MM-DD format | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @param {BNote} [rootNote] - specify calendar root note, normally leave empty to use default calendar | 
					
						
							|  |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2022-01-10 17:09:20 +01:00
										 |  |  |      * @deprecated use getDayNote instead | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-01-10 17:09:20 +01:00
										 |  |  |     this.getDateNote = dateNoteService.getDayNote; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Returns day note for given date. If such note doesn't exist, it is created. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} date in YYYY-MM-DD format | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @param {BNote} [rootNote] - specify calendar root note, normally leave empty to use default calendar | 
					
						
							|  |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2022-01-10 17:09:20 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.getDayNote = dateNoteService.getDayNote; | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 23:07:10 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Returns today's day note. If such note doesn't exist, it is created. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @param {BNote} [rootNote] - specify calendar root note, normally leave empty to use default calendar | 
					
						
							|  |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2019-11-27 23:07:10 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.getTodayNote = dateNoteService.getTodayNote; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-19 22:49:57 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Returns note for the first date of the week of the given date. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} date in YYYY-MM-DD format | 
					
						
							| 
									
										
										
										
											2022-10-26 14:23:56 +02:00
										 |  |  |      * @param {object} [options] - "startOfTheWeek" - either "monday" (default) or "sunday" | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @param {BNote} [rootNote] - specify calendar root note, normally leave empty to use default calendar | 
					
						
							|  |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2019-02-19 22:49:57 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.getWeekNote = dateNoteService.getWeekNote; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-19 21:29:41 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Returns month note for given date. If such note doesn't exist, it is created. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} date in YYYY-MM format | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @param {BNote} [rootNote] - specify calendar root note, normally leave empty to use default calendar | 
					
						
							|  |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2019-02-19 21:29:41 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.getMonthNote = dateNoteService.getMonthNote; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Returns year note for given year. If such note doesn't exist, it is created. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} year in YYYY format | 
					
						
							| 
									
										
										
										
											2023-01-03 13:52:37 +01:00
										 |  |  |      * @param {BNote} [rootNote] - specify calendar root note, normally leave empty to use default calendar | 
					
						
							|  |  |  |      * @returns {BNote|null} | 
					
						
							| 
									
										
										
										
											2019-02-19 21:29:41 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.getYearNote = dateNoteService.getYearNote; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @method | 
					
						
							| 
									
										
										
										
											2022-12-25 13:01:50 +01:00
										 |  |  |      * @deprecated - use sortNotes instead | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      * @param {string} parentNoteId - this note's child notes will be sorted | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-09-03 22:33:40 +02:00
										 |  |  |     this.sortNotesByTitle = parentNoteId => treeService.sortNotes(parentNoteId); | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-25 13:01:50 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Sort child notes of a given note. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} parentNoteId - this note's child notes will be sorted | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  |      * @param {object} [sortConfig] | 
					
						
							|  |  |  |      * @property {string} [sortConfig.sortBy=title] - 'title', 'dateCreated', 'dateModified' or a label name | 
					
						
							|  |  |  |      *                               see https://github.com/zadam/trilium/wiki/Sorting for details.
 | 
					
						
							|  |  |  |      * @property {boolean} [sortConfig.reverse=false] | 
					
						
							|  |  |  |      * @property {boolean} [sortConfig.foldersFirst=false] | 
					
						
							| 
									
										
										
										
											2022-12-25 13:01:50 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.sortNotes = (parentNoteId, sortConfig = {}) => treeService.sortNotes( | 
					
						
							|  |  |  |         parentNoteId, | 
					
						
							|  |  |  |         sortConfig.sortBy || "title", | 
					
						
							|  |  |  |         !!sortConfig.reverse, | 
					
						
							|  |  |  |         !!sortConfig.foldersFirst | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This method finds note by its noteId and prefix and either sets it to the given parentNoteId | 
					
						
							|  |  |  |      * or removes the branch (if parentNoteId is not given). | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							| 
									
										
										
										
											2019-11-10 19:29:51 +01:00
										 |  |  |      * @deprecated - this method is pretty confusing and serves specialized purpose only | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      * @param {string} noteId | 
					
						
							|  |  |  |      * @param {string} prefix | 
					
						
							| 
									
										
										
										
											2019-11-10 19:29:51 +01:00
										 |  |  |      * @param {string|null} parentNoteId | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.setNoteToParent = treeService.setNoteToParent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * This functions wraps code which is supposed to be running in transaction. If transaction already | 
					
						
							|  |  |  |      * exists, then we'll use that transaction. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							| 
									
										
										
										
											2018-08-23 12:55:45 +02:00
										 |  |  |      * @param {function} func | 
					
						
							| 
									
										
										
										
											2020-07-01 23:50:33 +02:00
										 |  |  |      * @returns {?} result of func callback | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.transactional = sql.transactional; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 22:01:52 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Return randomly generated string of given length. This random string generation is NOT cryptographically secure. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {number} length of the string | 
					
						
							|  |  |  |      * @returns {string} random string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     this.randomString = utils.randomString; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} string to escape | 
					
						
							|  |  |  |      * @returns {string} escaped string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     this.escapeHtml = utils.escapeHtml; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} string to unescape | 
					
						
							|  |  |  |      * @returns {string} unescaped string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     this.unescapeHtml = utils.unescapeHtml; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @property {module:sql} sql | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-11-30 22:28:30 +01:00
										 |  |  |     this.sql = sql; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2020-03-26 22:22:18 +01:00
										 |  |  |      * @method | 
					
						
							|  |  |  |      * @deprecated - this is now no-op since all the changes should be gracefully handled per widget | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-22 14:57:00 +01:00
										 |  |  |     this.refreshTree = () => { | 
					
						
							|  |  |  |         console.warn("api.refreshTree() is a NO-OP and can be removed from your script.") | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2019-01-18 23:57:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     this.getAppInfo = () => appInfo | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2022-12-22 14:57:00 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  |      * Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param {object} opts | 
					
						
							|  |  |  |      * @property {string} opts.id - id of the launcher, only alphanumeric at least 6 characters long | 
					
						
							|  |  |  |      * @property {string} opts.type - one of | 
					
						
							| 
									
										
										
										
											2022-12-22 14:57:00 +01:00
										 |  |  |      *                          * "note" - activating the launcher will navigate to the target note (specified in targetNoteId param) | 
					
						
							|  |  |  |      *                          * "script" -  activating the launcher will execute the script (specified in scriptNoteId param) | 
					
						
							|  |  |  |      *                          * "customWidget" - the launcher will be rendered with a custom widget (specified in widgetNoteId param) | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  |      * @property {string} opts.title | 
					
						
							|  |  |  |      * @property {boolean} [opts.isVisible=false] - if true, will be created in the "Visible launchers", otherwise in "Available launchers" | 
					
						
							|  |  |  |      * @property {string} [opts.icon] - name of the boxicon to be used (e.g. "bx-time") | 
					
						
							|  |  |  |      * @property {string} [opts.keyboardShortcut] - will activate the target note/script upon pressing, e.g. "ctrl+e" | 
					
						
							|  |  |  |      * @property {string} [opts.targetNoteId] - for type "note" | 
					
						
							|  |  |  |      * @property {string} [opts.scriptNoteId] - for type "script" | 
					
						
							|  |  |  |      * @property {string} [opts.widgetNoteId] - for type "customWidget" | 
					
						
							|  |  |  |      * @returns {{note: BNote}} | 
					
						
							| 
									
										
										
										
											2022-12-22 14:57:00 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.createOrUpdateLauncher = opts => { | 
					
						
							|  |  |  |         if (!opts.id) { throw new Error("ID is a mandatory parameter for api.createOrUpdateLauncher(opts)"); } | 
					
						
							|  |  |  |         if (!opts.id.match(/[a-z0-9]{6,1000}/i)) { throw new Error(`ID must be an alphanumeric string at least 6 characters long.`); } | 
					
						
							|  |  |  |         if (!opts.type) { throw new Error("Launcher Type is a mandatory parameter for api.createOrUpdateLauncher(opts)"); } | 
					
						
							|  |  |  |         if (!["note", "script", "customWidget"].includes(opts.type)) { throw new Error(`Given launcher type '${opts.type}'`); } | 
					
						
							|  |  |  |         if (!opts.title?.trim()) { throw new Error("Title is a mandatory parameter for api.createOrUpdateLauncher(opts)"); } | 
					
						
							|  |  |  |         if (opts.type === 'note' && !opts.targetNoteId) { throw new Error("targetNoteId is mandatory for launchers of type 'note'"); } | 
					
						
							|  |  |  |         if (opts.type === 'script' && !opts.scriptNoteId) { throw new Error("scriptNoteId is mandatory for launchers of type 'script'"); } | 
					
						
							|  |  |  |         if (opts.type === 'customWidget' && !opts.widgetNoteId) { throw new Error("widgetNoteId is mandatory for launchers of type 'customWidget'"); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const parentNoteId = !!opts.isVisible ? '_lbVisibleLaunchers' : '_lbAvailableLaunchers'; | 
					
						
							| 
									
										
										
										
											2022-12-23 20:40:58 +01:00
										 |  |  |         const noteId = 'al_' + opts.id; | 
					
						
							| 
									
										
										
										
											2022-12-22 14:57:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const launcherNote = | 
					
						
							|  |  |  |             becca.getNote(opts.id) || | 
					
						
							|  |  |  |             specialNotesService.createLauncher({ | 
					
						
							| 
									
										
										
										
											2022-12-23 20:40:58 +01:00
										 |  |  |                 noteId: noteId, | 
					
						
							| 
									
										
										
										
											2022-12-22 14:57:00 +01:00
										 |  |  |                 parentNoteId: parentNoteId, | 
					
						
							|  |  |  |                 launcherType: opts.type, | 
					
						
							|  |  |  |             }).note; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (launcherNote.title !== opts.title) { | 
					
						
							|  |  |  |             launcherNote.title = opts.title; | 
					
						
							|  |  |  |             launcherNote.save(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (launcherNote.getParentBranches().length === 1) { | 
					
						
							|  |  |  |             const branch = launcherNote.getParentBranches()[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (branch.parentNoteId !== parentNoteId) { | 
					
						
							|  |  |  |                 branchService.moveBranchToNote(branch, parentNoteId); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (opts.type === 'note') { | 
					
						
							|  |  |  |             launcherNote.setRelation('target', opts.targetNoteId); | 
					
						
							|  |  |  |         } else if (opts.type === 'script') { | 
					
						
							|  |  |  |             launcherNote.setRelation('script', opts.scriptNoteId); | 
					
						
							|  |  |  |         } else if (opts.type === 'customWidget') { | 
					
						
							|  |  |  |             launcherNote.setRelation('widget', opts.widgetNoteId); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             throw new Error(`Unrecognized launcher type '${opts.type}'`); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (opts.keyboardShortcut) { | 
					
						
							|  |  |  |             launcherNote.setLabel('keyboardShortcut', opts.keyboardShortcut); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             launcherNote.removeLabel('keyboardShortcut'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (opts.icon) { | 
					
						
							|  |  |  |             launcherNote.setLabel('iconClass', `bx ${opts.icon}`); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             launcherNote.removeLabel('keyboardShortcut'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-01-03 14:31:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return {note: launcherNote}; | 
					
						
							| 
									
										
										
										
											2022-12-22 14:57:00 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-29 21:15:34 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @method | 
					
						
							|  |  |  |      * @param {string} noteId | 
					
						
							|  |  |  |      * @param {string} format - either 'html' or 'markdown' | 
					
						
							|  |  |  |      * @param {string} zipFilePath | 
					
						
							| 
									
										
										
										
											2022-12-29 23:12:38 +01:00
										 |  |  |      * @returns {Promise} | 
					
						
							| 
									
										
										
										
											2022-12-29 21:15:34 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 23:12:38 +01:00
										 |  |  |     this.exportSubtreeToZipFile = async (noteId, format, zipFilePath) => await exportService.exportToZipFile(noteId, format, zipFilePath); | 
					
						
							| 
									
										
										
										
											2022-12-29 21:15:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-31 14:09:46 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * This object contains "at your risk" and "no BC guarantees" objects for advanced use cases. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-01-03 15:02:01 +01:00
										 |  |  |      * @property {Becca} becca - provides access to the backend in-memory object graph, see {@link https://github.com/zadam/trilium/blob/master/src/becca/becca.js}
 | 
					
						
							| 
									
										
										
										
											2022-05-31 14:09:46 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     this.__private = { | 
					
						
							|  |  |  |         becca | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-23 10:10:04 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-01 21:40:57 +02:00
										 |  |  | module.exports = BackendScriptApi; |