Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
small script API additions
zadam1c057cac75b3
diff --git a/docs/backend_api/BackendScriptApi.html b/docs/backend_api/BackendScriptApi.htmlindex d1cd08ae69..c1b498d326 100644--- a/docs/backend_api/BackendScriptApi.html+++ b/docs/backend_api/BackendScriptApi.html@@ -396,7 +396,7 @@ the backend.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line327">line 327</a>+ <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line335">line 335</a></li></ul></dd>@@ -1531,7 +1531,7 @@ JSON MIME type. See also createNote() for more options.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line332">line 332</a>+ <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line340">line 340</a></li></ul></dd>@@ -2763,7 +2763,7 @@ if some action needs to happen on only one specific instance.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line274">line 274</a>+ <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line282">line 282</a></li></ul></dd>@@ -3441,6 +3441,112 @@ if some action needs to happen on only one specific instance.+<h5>Returns:</h5>+++++<dl>+ <dt>+ Type+ </dt>+ <dd>++<span class="param-type">Promise.<(<a href="Note.html">Note</a>|null)></span>+++ </dd>+</dl>++++++++++++++ <h4 class="name" id="getTodayNote"><span class="type-signature"></span>getTodayNote<span class="signature">()</span><span class="type-signature"> → {Promise.<(<a href="Note.html">Note</a>|null)>}</span></h4>+++++++<div class="description">+ Returns today's day note. If such note doesn't exist, it is created.+</div>++++++++++++++<dl class="details">+++++++++++++++++++++++++++ <dt class="tag-source">Source:</dt>+ <dd class="tag-source"><ul class="dummy"><li>+ <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line263">line 263</a>+ </li></ul></dd>++++++++</dl>+++++++++++++++<h5>Returns:</h5>@@ -3594,7 +3700,7 @@ if some action needs to happen on only one specific instance.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line265">line 265</a>+ <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line273">line 273</a></li></ul></dd>@@ -3749,7 +3855,7 @@ if some action needs to happen on only one specific instance.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line283">line 283</a>+ <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line291">line 291</a></li></ul></dd>@@ -4402,7 +4508,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line304">line 304</a>+ <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line312">line 312</a></li></ul></dd>@@ -4535,7 +4641,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line290">line 290</a>+ <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line298">line 298</a></li></ul></dd>@@ -4910,7 +5016,7 @@ transactional by default.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line317">line 317</a>+ <a href="services_backend_script_api.js.html">services/backend_script_api.js</a>, <a href="services_backend_script_api.js.html#line325">line 325</a></li></ul></dd>diff --git a/docs/backend_api/Note.html b/docs/backend_api/Note.htmlindex 141ac63031..dabe2ae48e 100644--- a/docs/backend_api/Note.html+++ b/docs/backend_api/Note.html@@ -5523,6 +5523,156 @@ Cache is note instance scoped.+++++++ <h4 class="name" id="isDescendantOfNote"><span class="type-signature">(async) </span>isDescendantOfNote<span class="signature">(ancestorNoteId)</span><span class="type-signature"> → {Promise.<boolean>}</span></h4>+++++++++++++++ <h5>Parameters:</h5>+++<table class="params">+ <thead>+ <tr>++ <th>Name</th>+++ <th>Type</th>++++++ <th class="last">Description</th>+ </tr>+ </thead>++ <tbody>+++ <tr>++ <td class="name"><code>ancestorNoteId</code></td>+++ <td class="type">++ </td>++++++ <td class="description last"></td>+ </tr>+++ </tbody>+</table>+++++++<dl class="details">+++++++++++++++++++++++++++ <dt class="tag-source">Source:</dt>+ <dd class="tag-source"><ul class="dummy"><li>+ <a href="entities_note.js.html">entities/note.js</a>, <a href="entities_note.js.html#line785">line 785</a>+ </li></ul></dd>++++++++</dl>++++++++++++++++<h5>Returns:</h5>+++<div class="param-desc">+ - true if ancestorNoteId occurs in at least one of the note's paths+</div>++++<dl>+ <dt>+ Type+ </dt>+ <dd>++<span class="param-type">Promise.<boolean></span>+++ </dd>+</dl>+++++++diff --git a/docs/backend_api/entities_note.js.html b/docs/backend_api/entities_note.js.htmlindex 4f4029bde9..9f32a00eea 100644--- a/docs/backend_api/entities_note.js.html+++ b/docs/backend_api/entities_note.js.html@@ -806,6 +806,16 @@ class Note extends Entity {return notePaths;}+ /**+ * @param ancestorNoteId+ * @return {Promise<boolean>} - true if ancestorNoteId occurs in at least one of the note's paths+ */+ async isDescendantOfNote(ancestorNoteId) {+ const notePaths = await this.getAllNotePaths();++ return notePaths.some(path => path.includes(ancestorNoteId));+ }+beforeSaving() {if (!this.isDeleted) {this.isDeleted = false;@@ -846,6 +856,7 @@ class Note extends Entity {delete pojo.isContentAvailable;delete pojo.__attributeCache;delete pojo.content;+ /** zero references to contentHash, probably can be removed */delete pojo.contentHash;}}diff --git a/docs/backend_api/services_backend_script_api.js.html b/docs/backend_api/services_backend_script_api.js.htmlindex 725fe064ea..edc16a6827 100644--- a/docs/backend_api/services_backend_script_api.js.html+++ b/docs/backend_api/services_backend_script_api.js.html@@ -282,6 +282,14 @@ function BackendScriptApi(currentNote, apiParams) {*/this.getDateNote = dateNoteService.getDateNote;+ /**+ * Returns today's day note. If such note doesn't exist, it is created.+ *+ * @method+ * @returns {Promise<Note|null>}+ */+ this.getTodayNote = dateNoteService.getTodayNote;+/*** Returns note for the first date of the week of the given date.*diff --git a/src/entities/note.js b/src/entities/note.jsindex c89ea0f239..e9d4e1aba3 100644--- a/src/entities/note.js+++ b/src/entities/note.js@@ -778,6 +778,16 @@ class Note extends Entity {return notePaths;}+ /**+ * @param ancestorNoteId+ * @return {Promise<boolean>} - true if ancestorNoteId occurs in at least one of the note's paths+ */+ async isDescendantOfNote(ancestorNoteId) {+ const notePaths = await this.getAllNotePaths();++ return notePaths.some(path => path.includes(ancestorNoteId));+ }+beforeSaving() {if (!this.isDeleted) {this.isDeleted = false;diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.jsindex 36bb247ae9..08e8890b5a 100644--- a/src/services/backend_script_api.js+++ b/src/services/backend_script_api.js@@ -254,6 +254,14 @@ function BackendScriptApi(currentNote, apiParams) {*/this.getDateNote = dateNoteService.getDateNote;+ /**+ * Returns today's day note. If such note doesn't exist, it is created.+ *+ * @method+ * @returns {Promise<Note|null>}+ */+ this.getTodayNote = dateNoteService.getTodayNote;+/*** Returns note for the first date of the week of the given date.*diff --git a/src/services/date_notes.js b/src/services/date_notes.jsindex fffb62e4a2..265048705d 100644--- a/src/services/date_notes.js+++ b/src/services/date_notes.js@@ -170,6 +170,10 @@ async function getDateNote(dateStr) {return dateNote;}+async function getTodayNote() {+ return await getDateNote(dateUtils.localNowDate());+}+function getStartOfTheWeek(date, startOfTheWeek) {const day = date.getDay();let diff;@@ -202,5 +206,6 @@ module.exports = {getYearNote,getMonthNote,getWeekNote,- getDateNote+ getDateNote,+ getTodayNote};\ No newline at end of file