Skip to content

Build your personal knowledge base with Trilium Notes

fixes

zadam3e189d5c1051
diff --git a/db/demo.zip b/db/demo.zip
index 80827909a6..1965708ab1 100644
Binary files a/db/demo.zip and b/db/demo.zip differ
diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js
index 1824952067..eaf9f10db6 100644
--- a/src/services/backend_script_api.js
+++ b/src/services/backend_script_api.js
@@ -50,28 +50,28 @@ function BackendScriptApi(currentNote, apiParams) {
/**
* @method
* @param {string} noteId
- * @returns {Promise<Note|null>}
+ * @returns {Note|null}
*/
this.getNote = repository.getNote;
/**
* @method
* @param {string} branchId
- * @returns {Promise<Branch|null>}
+ * @returns {Branch|null}
*/
this.getBranch = repository.getBranch;
/**
* @method
* @param {string} attributeId
- * @returns {Promise<Attribute|null>}
+ * @returns {Attribute|null}
*/
this.getAttribute = repository.getAttribute;
/**
* @method
* @param {string} imageId
- * @returns {Promise<Image|null>}
+ * @returns {Image|null}
*/
this.getImage = repository.getImage;
@@ -81,7 +81,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @method
* @param {string} SQL query
* @param {Array.<?>} array of params
- * @returns {Promise<Entity|null>}
+ * @returns {Entity|null}
*/
this.getEntity = repository.getEntity;
@@ -89,7 +89,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @method
* @param {string} SQL query
* @param {Array.<?>} array of params
- * @returns {Promise<Entity[]>}
+ * @returns {Entity[]}
*/
this.getEntities = repository.getEntities;
@@ -109,7 +109,7 @@ function BackendScriptApi(currentNote, apiParams) {
*
* @method
* @param {string} searchString
- * @returns {Promise<Note|null>}
+ * @returns {Note|null}
*/
this.searchForNote = searchString => {
const notes = searchService.searchNoteEntities(searchString);
@@ -123,7 +123,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @method
* @param {string} name - attribute name
* @param {string} [value] - attribute value
- * @returns {Promise<Note[]>}
+ * @returns {Note[]}
*/
this.getNotesWithLabel = attributeService.getNotesWithLabel;
@@ -133,7 +133,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @method
* @param {string} name - attribute name
* @param {string} [value] - attribute value
- * @returns {Promise<Note|null>}
+ * @returns {Note|null}
*/
this.getNoteWithLabel = attributeService.getNoteWithLabel;
@@ -144,7 +144,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @param {string} noteId
* @param {string} parentNoteId
* @param {string} prefix - if branch will be create between note and parent note, set this prefix
- * @returns {Promise<void>}
+ * @returns {void}
*/
this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent;
@@ -154,7 +154,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @method
* @param {string} noteId
* @param {string} parentNoteId
- * @returns {Promise<void>}
+ * @returns {void}
*/
this.ensureNoteIsAbsentFromParent = cloningService.ensureNoteIsAbsentFromParent;
@@ -166,7 +166,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @param {string} noteId
* @param {string} parentNoteId
* @param {string} prefix - if branch will be create between note and parent note, set this prefix
- * @returns {Promise<void>}
+ * @returns {void}
*/
this.toggleNoteInParent = cloningService.toggleNoteInParent;
@@ -183,7 +183,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @param {string} parentNoteId
* @param {string} title
* @param {string} content
- * @return {Promise<{note: Note, branch: Branch}>}
+ * @return {{note: Note, branch: Branch}}
*/
this.createTextNote = (parentNoteId, title, content = '') => noteService.createNewNote({
parentNoteId,
@@ -199,7 +199,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @param {string} parentNoteId
* @param {string} title
* @param {object} content
- * @return {Promise<{note: Note, branch: Branch}>}
+ * @return {{note: Note, branch: Branch}}
*/
this.createDataNote = (parentNoteId, title, content = {}) => noteService.createNewNote({
parentNoteId,
@@ -226,7 +226,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @method
*
* @param {CreateNewNoteParams} [params]
- * @returns {Promise<{note: Note, branch: Branch}>} object contains newly created entities note and branch
+ * @returns {{note: Note, branch: Branch}} object contains newly created entities note and branch
*/
this.createNewNote = noteService.createNewNote;
@@ -254,7 +254,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @param {string} title
* @param {string} [content=""]
* @param {CreateNoteExtraOptions} [extraOptions={}]
- * @returns {Promise<{note: Note, branch: Branch}>} object contains newly created entities note and branch
+ * @returns {{note: Note, branch: Branch}} object contains newly created entities note and branch
*/
this.createNote = (parentNoteId, title, content = "", extraOptions= {}) => {
extraOptions.parentNoteId = parentNoteId;
@@ -301,7 +301,7 @@ function BackendScriptApi(currentNote, apiParams) {
* Returns root note of the calendar.
*
* @method
- * @returns {Promise<Note|null>}
+ * @returns {Note|null}
*/
this.getRootCalendarNote = dateNoteService.getRootCalendarNote;
@@ -310,7 +310,7 @@ function BackendScriptApi(currentNote, apiParams) {
*
* @method
* @param {string} date in YYYY-MM-DD format
- * @returns {Promise<Note|null>}
+ * @returns {Note|null}
*/
this.getDateNote = dateNoteService.getDateNote;
@@ -318,7 +318,7 @@ function BackendScriptApi(currentNote, apiParams) {
* Returns today's day note. If such note doesn't exist, it is created.
*
* @method
- * @returns {Promise<Note|null>}
+ * @returns {Note|null}
*/
this.getTodayNote = dateNoteService.getTodayNote;
@@ -328,7 +328,7 @@ function BackendScriptApi(currentNote, apiParams) {
* @method
* @param {string} date in YYYY-MM-DD format
* @param {object} options - "startOfTheWeek" - either "monday" (default) or "sunday"
- * @returns {Promise<Note|null>}
+ * @returns {Note|null}
*/
this.getWeekNote = dateNoteService.getWeekNote;
@@ -337,7 +337,7 @@ function BackendScriptApi(currentNote, apiParams) {
*
* @method
* @param {string} date in YYYY-MM format
- * @returns {Promise<Note|null>}
+ * @returns {Note|null}
*/
this.getMonthNote = dateNoteService.getMonthNote;
@@ -346,14 +346,13 @@ function BackendScriptApi(currentNote, apiParams) {
*
* @method
* @param {string} year in YYYY format
- * @returns {Promise<Note|null>}
+ * @returns {Note|null}
*/
this.getYearNote = dateNoteService.getYearNote;
/**
* @method
* @param {string} parentNoteId - this note's child notes will be sorted
- * @returns Promise<void>
*/
this.sortNotesAlphabetically = treeService.sortNotesAlphabetically;
@@ -380,7 +379,7 @@ function BackendScriptApi(currentNote, apiParams) {
*
* @method
* @param {function} func
- * @returns {Promise<?>} result of func callback
+ * @returns {?} result of func callback
*/
this.transactional = sql.transactional;
diff --git a/src/services/date_notes.js b/src/services/date_notes.js
index f8317a93d3..1c3027b272 100644
--- a/src/services/date_notes.js
+++ b/src/services/date_notes.js
@@ -30,20 +30,20 @@ function getNoteStartingWith(parentNoteId, startsWith) {
AND branches.isDeleted = 0`, [parentNoteId]);
}
-/** @return {Promise<Note>} */
+/** @return {Note} */
function getRootCalendarNote() {
// some caching here could be useful (e.g. in CLS)
let rootNote = attributeService.getNoteWithLabel(CALENDAR_ROOT_LABEL);
if (!rootNote) {
- rootNote = (noteService.createNewNote({
+ rootNote = noteService.createNewNote({
parentNoteId: 'root',
title: 'Calendar',
target: 'into',
isProtected: false,
type: 'text',
content: ''
- })).note;
+ }).note;
attributeService.createLabel(rootNote.noteId, CALENDAR_ROOT_LABEL);
attributeService.createLabel(rootNote.noteId, 'sorted');
@@ -52,7 +52,7 @@ function getRootCalendarNote() {
return rootNote;
}
-/** @return {Promise<Note>} */
+/** @return {Note} */
function getYearNote(dateStr, rootNote) {
if (!rootNote) {
rootNote = getRootCalendarNote();
@@ -91,7 +91,7 @@ function getMonthNoteTitle(rootNote, monthNumber, dateObj) {
.replace(/{month}/g, monthName);
}
-/** @return {Promise<Note>} */
+/** @return {Note} */
function getMonthNote(dateStr, rootNote) {
if (!rootNote) {
rootNote = getRootCalendarNote();
@@ -139,7 +139,7 @@ function getDateNoteTitle(rootNote, dayNumber, dateObj) {
.replace(/{weekDay2}/g, weekDay.substr(0, 2));
}
-/** @return {Promise<Note>} */
+/** @return {Note} */
function getDateNote(dateStr) {
const rootNote = getRootCalendarNote();
diff --git a/src/services/import/zip.js b/src/services/import/zip.js
index 3db74fe4d5..58fcf08931 100644
--- a/src/services/import/zip.js
+++ b/src/services/import/zip.js
@@ -330,6 +330,17 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
}
}
+ if (type === 'text' && noteMeta) {
+ const includeNoteLinks = (noteMeta.attributes || [])
+ .filter(attr => attr.type === 'relation' && attr.name === 'includeNoteLink');
+
+ // this will replace relation map links
+ for (const link of includeNoteLinks) {
+ // no need to escape the regexp find string since it's a noteId which doesn't contain any special characters
+ content = content.replace(new RegExp(link.value, "g"), getNewNoteId(link.value));
+ }
+ }
+
let note = repository.getNote(noteId);
if (note) {
diff --git a/src/services/repository.js b/src/services/repository.js
index 1a32d30de5..93df1ff325 100644
--- a/src/services/repository.js
+++ b/src/services/repository.js
@@ -44,12 +44,12 @@ function getCachedEntity(entityName, entityId, query) {
return entity;
}
-/** @returns {Promise<Note|null>} */
+/** @returns {Note|null} */
function getNote(noteId) {
return getCachedEntity('notes', noteId, "SELECT * FROM notes WHERE noteId = ?");
}
-/** @returns {Promise<Note[]>} */
+/** @returns {Note[]} */
function getNotes(noteIds) {
// this note might be optimised, but remember that it must keep the existing order of noteIds
// (important e.g. for @orderBy in search)
@@ -64,22 +64,22 @@ function getNotes(noteIds) {
return notes;
}
-/** @returns {Promise<NoteRevision|null>} */
+/** @returns {NoteRevision|null} */
function getNoteRevision(noteRevisionId) {
return getCachedEntity('note_revisions', noteRevisionId, "SELECT * FROM note_revisions WHERE noteRevisionId = ?");
}
-/** @returns {Promise<Branch|null>} */
+/** @returns {Branch|null} */
function getBranch(branchId) {
return getCachedEntity('branches', branchId, "SELECT * FROM branches WHERE branchId = ?", [branchId]);
}
-/** @returns {Promise<Attribute|null>} */
+/** @returns {Attribute|null} */
function getAttribute(attributeId) {
return getCachedEntity('attributes', attributeId, "SELECT * FROM attributes WHERE attributeId = ?");
}
-/** @returns {Promise<Option|null>} */
+/** @returns {Option|null} */
function getOption(name) {
return getEntity("SELECT * FROM options WHERE name = ?", [name]);
}