2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								<!DOCTYPE html>  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< html  lang = "en" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< head >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < meta  charset = "utf-8" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < title > JSDoc: Source: services/backend_script_api.js< / title > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < script  src = "scripts/prettify/prettify.js" >  < / script > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < script  src = "scripts/prettify/lang-css.js" >  < / script > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <!-- [if lt IE 9]>
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < script  src = "//html5shiv.googlecode.com/svn/trunk/html5.js" > < / script > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    <![endif]--> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < link  type = "text/css"  rel = "stylesheet"  href = "styles/prettify-tomorrow.css" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < link  type = "text/css"  rel = "stylesheet"  href = "styles/jsdoc-default.css" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / head >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< body >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = "main" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < h1  class = "page-title" > Source: services/backend_script_api.js< / h1 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < article > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            < pre  class = "prettyprint source linenums" > < code > 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-07 22:01:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const xml2js = require('xml2js');
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								const cloningService = require('./cloning');
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const appInfo = require('./app_info');
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const searchService = require('./search/services/search');
							 
						 
					
						
							
								
									
										
										
										
											2021-09-30 12:26:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const SearchContext = require("./search/search_context");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const becca = require("../becca/becca");
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * This is the main backend API interface for scripts. It's published in the local "api" object.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * @constructor
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * @hideconstructor
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function BackendScriptApi(currentNote, apiParams) {
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /** @property {Note} note where script started executing */
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.startNote = apiParams.startNote;
							 
						 
					
						
							
								
									
										
										
										
											2019-03-14 20:49:10 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /** @property {Note} note where script is currently executing. Don't mix this up with concept of active note */
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this.currentNote = currentNote;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /** @property {Entity} entity whose event triggered this executions */
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.originEntity = apiParams.originEntity;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for (const key in apiParams) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        this[key] = apiParams[key];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +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-29 20:44:35 +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 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.xml2js = xml2js;
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-07 22:01:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // DEPRECATED - use direct api.unescapeHtml
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this.utils = {
							 
						 
					
						
							
								
									
										
										
										
											2019-03-14 20:49:10 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        unescapeHtml: utils.unescapeHtml
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +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
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note|null}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2021-11-10 21:30:54 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.getNote = noteId => becca.getNote(noteId);
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} branchId
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Branch|null}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2021-11-10 21:30:54 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.getBranch = branchId => becca.getBranch(branchId);
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} attributeId
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Attribute|null}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2021-11-10 21:30:54 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.getAttribute = attributeId => becca.getAttribute(attributeId);
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +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-30 22:48:30 +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-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @param {string} query
							 
						 
					
						
							
								
									
										
										
										
											2021-02-17 23:55:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @param {Object} [searchParams]
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note[]}
							 
						 
					
						
							
								
									
										
										
										
											2019-03-20 22:51:13 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2021-02-17 23:55:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.searchForNotes = (query, searchParams = {}) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if (searchParams.includeArchivedNotes === undefined) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            searchParams.includeArchivedNotes = true;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-07 22:01:52 +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-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            .map(sr => sr.noteId);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-30 12:26:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return becca.getNotes(noteIds);
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +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-30 22:48:30 +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-09-30 12:26:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @param {string} query
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {Object} [searchParams]
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note|null}
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 18:08:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2021-09-30 12:26:13 +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-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * Retrieves notes with given label name &  value
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} name - attribute name
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} [value] - attribute value
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note[]}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +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
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note|null}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.getNoteWithLabel = attributeService.getNoteWithLabel;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * If there's no branch between note and parent note, create one. Otherwise do nothing.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} noteId
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} parentNoteId
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} prefix - if branch will be create between note and parent note, set this prefix
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {void}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * If there's a branch between note and parent note, remove it. Otherwise do nothing.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} noteId
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} parentNoteId
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {void}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +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-05 20:31:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @param {string} prefix - if branch will be created between note and parent note, set this prefix
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {void}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.toggleNoteInParent = cloningService.toggleNoteInParent;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @typedef {object} CreateNoteAttribute
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} type - attribute type - label, relation etc.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} name - attribute name
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} [value] - attribute value
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-25 22:45:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
									
										
										
										
											2019-11-28 22:35:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * Create text note. See also createNewNote() for more options.
							 
						 
					
						
							
								
									
										
										
										
											2019-11-25 22:45:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} parentNoteId
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} title
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} content
							 
						 
					
						
							
								
									
										
										
										
											2021-04-07 22:01:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @return {{note: Note, branch: Branch}} - object having "note" and "branch" keys representing respective objects
							 
						 
					
						
							
								
									
										
										
										
											2019-11-25 22:45:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.createTextNote = (parentNoteId, title, content = '') => noteService.createNewNote({
							 
						 
					
						
							
								
									
										
										
										
											2019-11-25 22:45:09 +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 22:45:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} parentNoteId
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} title
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {object} content
							 
						 
					
						
							
								
									
										
										
										
											2021-04-07 22:01:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @return {{note: Note, branch: Branch}} object having "note" and "branch" keys representing respective objects
							 
						 
					
						
							
								
									
										
										
										
											2019-11-25 22:45:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.createDataNote = (parentNoteId, title, content = {}) => noteService.createNewNote({
							 
						 
					
						
							
								
									
										
										
										
											2019-11-25 22:45:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        parentNoteId,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        title,
							 
						 
					
						
							
								
									
										
										
										
											2020-01-04 21:53:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        content: JSON.stringify(content, null, '\t'),
							 
						 
					
						
							
								
									
										
										
										
											2019-11-25 22:45:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        type: 'code',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        mime: 'application/json'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
									
										
										
										
											2019-11-28 22:35:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @typedef {object} CreateNewNoteParams
							 
						 
					
						
							
								
									
										
										
										
											2019-11-25 22:45:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @property {string} parentNoteId - MANDATORY
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} title - MANDATORY
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string|buffer} content - MANDATORY
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} type - text, code, file, image, search, book, relation-map - MANDATORY
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} mime - value is derived from default mimes for type
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {boolean} isProtected - default is false
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {boolean} isExpanded - default is false
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} prefix - default is empty string
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {int} notePosition - default is last existing notePosition in a parent + 10
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
									
										
										
										
											2019-11-28 22:35:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @param {CreateNewNoteParams} [params]
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {{note: Note, branch: Branch}} object contains newly created entities note and branch
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2019-11-28 22:35:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.createNewNote = noteService.createNewNote;
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-12-03 22:53:17 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @typedef {object} CreateNoteAttribute
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} type - attribute type - label, relation etc.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} name - attribute name
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} [value] - attribute value
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @typedef {object} CreateNoteExtraOptions
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {boolean} [json=false] - should the note be JSON
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {boolean} [isProtected=false] - should the note be protected
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} [type='text'] - note type
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {string} [mime='text/html'] - MIME type of the note
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @property {CreateNoteAttribute[]} [attributes=[]] - attributes to be created for this note
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @deprecated please use createTextNote() with similar API for simpler use cases or createNewNote() for more complex needs
							 
						 
					
						
							
								
									
										
										
										
											2019-12-03 22:53:17 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} parentNoteId - create new note under this parent
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} title
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} [content=""]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {CreateNoteExtraOptions} [extraOptions={}]
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {{note: Note, branch: Branch}} object contains newly created entities note and branch
							 
						 
					
						
							
								
									
										
										
										
											2019-12-03 22:53:17 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.createNote = (parentNoteId, title, content = "", extraOptions= {}) => {
							 
						 
					
						
							
								
									
										
										
										
											2019-12-03 22:53:17 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        extraOptions.parentNoteId = parentNoteId;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        extraOptions.title = title;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-09-30 12:26:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const parentNote = becca.getNote(parentNoteId);
							 
						 
					
						
							
								
									
										
										
										
											2019-12-03 22:53:17 +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:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return sql.transactional(() => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            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 22:53:17 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * Log given message to trilium logs.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param message
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.log = message => log.info(`Script "${currentNote.title}" (${currentNote.noteId}): ${message}`);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * Returns root note of the calendar.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note|null}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.getRootCalendarNote = dateNoteService.getRootCalendarNote;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * Returns day note for given date. If such note doesn't exist, it is created.
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @param {string} date in YYYY-MM-DD format
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note|null}
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.getDateNote = dateNoteService.getDateNote;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-27 23:07:10 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * Returns today's day note. If such note doesn't exist, it is created.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note|null}
							 
						 
					
						
							
								
									
										
										
										
											2019-11-27 23:07:10 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.getTodayNote = dateNoteService.getTodayNote;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * Returns note for the first date of the week of the given date.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} date in YYYY-MM-DD format
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {object} options - "startOfTheWeek" - either "monday" (default) or "sunday"
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note|null}
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.getWeekNote = dateNoteService.getWeekNote;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * Returns month note for given date. If such note doesn't exist, it is created.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} date in YYYY-MM format
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note|null}
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +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
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {Note|null}
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.getYearNote = dateNoteService.getYearNote;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} parentNoteId - this note's child notes will be sorted
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2021-09-30 12:26:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.sortNotesByTitle = parentNoteId => treeService.sortNotes(parentNoteId);
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +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:34:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @deprecated - this method is pretty confusing and serves specialized purpose only
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     * @param {string} noteId
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {string} prefix
							 
						 
					
						
							
								
									
										
										
										
											2019-11-10 19:34:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @param {string|null} parentNoteId
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +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
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @param {function} func
							 
						 
					
						
							
								
									
										
										
										
											2020-09-30 22:48:30 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @returns {?} result of func callback
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +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-12-22 22:28:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.sql = sql;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
									
										
										
										
											2020-04-07 19:19:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     * @method
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @deprecated - this is now no-op since all the changes should be gracefully handled per widget
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
									
										
										
										
											2020-04-07 19:19:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    this.refreshTree = () => {};
							 
						 
					
						
							
								
									
										
										
										
											2019-02-20 22:24:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.getAppInfo = () => appInfo
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-06 21:35:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								module.exports = BackendScriptApi;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / code > < / pre >  
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        < / article > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / section > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< nav >  
						 
					
						
							
								
									
										
										
										
											2022-01-05 20:31:21 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    < h2 > < a  href = "index.html" > Home< / a > < / h2 > < h3 > Modules< / h3 > < ul > < li > < a  href = "sql%250A%250ATODO_%2520some%2520methods%2520(like%2520getValue())%2520could%2520use%2520raw%2520rowsmodule_.html" > sql
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								TODO: some methods (like getValue()) could use raw rows< / a > < / li > < / ul > < h3 > Classes< / h3 > < ul > < li > < a  href = "ApiToken.html" > ApiToken< / a > < / li > < li > < a  href = "Attribute.html" > Attribute< / a > < / li > < li > < a  href = "BackendScriptApi.html" > BackendScriptApi< / a > < / li > < li > < a  href = "Branch.html" > Branch< / a > < / li > < li > < a  href = "Note.html" > Note< / a > < / li > < li > < a  href = "NoteRevision.html" > NoteRevision< / a > < / li > < li > < a  href = "Option.html" > Option< / a > < / li > < li > < a  href = "RecentNote.html" > RecentNote< / a > < / li > < / ul > < h3 > < a  href = "global.html" > Global< / a > < / h3 > 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / nav >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< br  class = "clear" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< footer >  
						 
					
						
							
								
									
										
										
										
											2021-09-30 12:26:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Documentation generated by < a  href = "https://github.com/jsdoc/jsdoc" > JSDoc 3.6.7< / a > 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 20:44:35 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / footer >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< script >  prettyPrint ( ) ;  < / script >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< script  src = "scripts/linenumber.js" >  < / script >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / body >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / html >