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
moving from inherited attribute queries to owned one where it makes sense
zadamd9b9d730bb9b
diff --git a/src/entities/note.js b/src/entities/note.jsindex 5673008040..5b7067e7d9 100644--- a/src/entities/note.js+++ b/src/entities/note.js@@ -278,6 +278,14 @@ class Note extends Entity {return await this.getAttributes(LABEL, name);}+ /**+ * @param {string} [name] - label name to filter+ * @returns {Promise<Attribute[]>} all note's labels (attributes with type label), excluding inherited ones+ */+ async getOwnedLabels(name) {+ return await this.getOwnedAttributes(LABEL, name);+ }+/*** @param {string} [name] - label name to filter* @returns {Promise<Attribute[]>} all note's label definitions, including inherited ones@@ -294,6 +302,14 @@ class Note extends Entity {return await this.getAttributes(RELATION, name);}+ /**+ * @param {string} [name] - relation name to filter+ * @returns {Promise<Attribute[]>} all note's relations (attributes with type relation), excluding inherited ones+ */+ async getOwnedRelations(name) {+ return await this.getOwnedAttributes(RELATION, name);+ }+/*** @param {string} [name] - relation name to filter* @returns {Promise<Note[]>}diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.jsindex ffdb4b363f..1554941c3a 100644--- a/src/routes/api/clipper.js+++ b/src/routes/api/clipper.js@@ -15,7 +15,7 @@ async function findClippingNote(todayNote, pageUrl) {const notes = await todayNote.getDescendantNotesWithLabel('pageUrl', pageUrl);for (const note of notes) {- if (await note.getLabelValue('clipType') === 'clippings') {+ if (await note.getOwnedLabelValue('clipType') === 'clippings') {return note;}}diff --git a/src/routes/api/notes.js b/src/routes/api/notes.jsindex d010043888..c9de2783f1 100644--- a/src/routes/api/notes.js+++ b/src/routes/api/notes.js@@ -27,31 +27,6 @@ async function getNote(req) {return note;}-async function getChildren(req) {- const parentNoteId = req.params.parentNoteId;- const parentNote = await repository.getNote(parentNoteId);-- if (!parentNote) {- return [404, `Note ${parentNoteId} has not been found.`];- }-- const ret = [];-- for (const childNote of await parentNote.getChildNotes()) {- ret.push({- noteId: childNote.noteId,- title: childNote.title,- relations: (await childNote.getRelations()).map(relation => { return {- attributeId: relation.attributeId,- name: relation.name,- targetNoteId: relation.value- }; })- });- }-- return ret;-}-async function createNote(req) {const params = Object.assign({}, req.body); // cloneparams.parentNoteId = req.params.parentNoteId;@@ -198,7 +173,6 @@ module.exports = {sortNotes,protectSubtree,setNoteTypeMime,- getChildren,getRelationMap,changeTitle,duplicateNotediff --git a/src/routes/api/options.js b/src/routes/api/options.jsindex 09ee01532d..384b5f3760 100644--- a/src/routes/api/options.js+++ b/src/routes/api/options.js@@ -90,7 +90,7 @@ async function getUserThemes() {const ret = [];for (const note of notes) {- let value = await note.getLabelValue('appTheme');+ let value = await note.getOwnedLabelValue('appTheme');if (!value) {value = note.title.toLowerCase().replace(/[^a-z0-9]/gi, '-');diff --git a/src/routes/routes.js b/src/routes/routes.jsindex 725d07ae50..fb8f1ebdfb 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -128,7 +128,6 @@ function register(app) {apiRoute(PUT, '/api/notes/:noteId', notesApiRoute.updateNote);apiRoute(DELETE, '/api/notes/:noteId', notesApiRoute.deleteNote);apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote);- apiRoute(GET, '/api/notes/:parentNoteId/children', notesApiRoute.getChildren);apiRoute(PUT, '/api/notes/:noteId/sort', notesApiRoute.sortNotes);apiRoute(PUT, '/api/notes/:noteId/protect/:isProtected', notesApiRoute.protectSubtree);apiRoute(PUT, /\/api\/notes\/(.*)\/type\/(.*)\/mime\/(.*)/, notesApiRoute.setNoteTypeMime);diff --git a/src/services/date_notes.js b/src/services/date_notes.jsindex 265048705d..d6b1a396ba 100644--- a/src/services/date_notes.js+++ b/src/services/date_notes.js@@ -81,7 +81,7 @@ async function getYearNote(dateStr, rootNote) {}async function getMonthNoteTitle(rootNote, monthNumber, dateObj) {- const pattern = await rootNote.getLabelValue("monthPattern") || "{monthNumberPadded} - {month}";+ const pattern = await rootNote.getOwnedLabelValue("monthPattern") || "{monthNumberPadded} - {month}";const monthName = MONTHS[dateObj.getMonth()];return pattern@@ -127,7 +127,7 @@ async function getMonthNote(dateStr, rootNote) {}async function getDateNoteTitle(rootNote, dayNumber, dateObj) {- const pattern = await rootNote.getLabelValue("datePattern") || "{dayInMonthPadded} - {weekDay}";+ const pattern = await rootNote.getOwnedLabelValue("datePattern") || "{dayInMonthPadded} - {weekDay}";const weekDay = DAYS[dateObj.getDay()];return patterndiff --git a/src/services/export/opml.js b/src/services/export/opml.jsindex 16399da5b0..e784081174 100644--- a/src/services/export/opml.js+++ b/src/services/export/opml.js@@ -16,7 +16,7 @@ async function exportToOpml(taskContext, branch, version, res) {const branch = await repository.getBranch(branchId);const note = await branch.getNote();- if (!note.isStringNote() || await note.hasLabel('excludeFromExport')) {+ if (!note.isStringNote() || await note.hasOwnedLabel('excludeFromExport')) {return;}diff --git a/src/services/export/tar.js b/src/services/export/tar.jsindex db8ffbc026..441f62d9db 100644--- a/src/services/export/tar.js+++ b/src/services/export/tar.js@@ -79,7 +79,7 @@ async function exportToTar(taskContext, branch, format, res) {async function getNoteMeta(branch, parentMeta, existingFileNames) {const note = await branch.getNote();- if (await note.hasLabel('excludeFromExport')) {+ if (await note.hasOwnedLabel('excludeFromExport')) {return;}diff --git a/src/services/handlers.js b/src/services/handlers.jsindex 634844e088..12ac55afb6 100644--- a/src/services/handlers.js+++ b/src/services/handlers.js@@ -27,7 +27,7 @@ eventService.subscribe(eventService.NOTE_TITLE_CHANGED, async note => {const parents = await note.getParentNotes();for (const parent of parents) {- if (await parent.hasLabel("sorted")) {+ if (await parent.hasOwnedLabel("sorted")) {await treeService.sortNotesAlphabetically(parent.noteId);}}@@ -119,7 +119,7 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({ entityName, entityeventService.subscribe(eventService.ENTITY_DELETED, async ({ entityName, entity }) => {await processInverseRelations(entityName, entity, async (definition, note, targetNote) => {// if one inverse attribute is deleted then the other should be deleted as well- const relations = await targetNote.getRelations(definition.inverseRelation);+ const relations = await targetNote.getOwnedRelations(definition.inverseRelation);let deletedSomething = false;for (const relation of relations) {diff --git a/src/services/script.js b/src/services/script.jsindex 5a3949d0be..153d535aaf 100644--- a/src/services/script.js+++ b/src/services/script.js@@ -40,7 +40,7 @@ async function executeBundle(bundle, apiParams = {}) {const ctx = new ScriptContext(bundle.allNotes, apiParams);try {- if (await bundle.note.hasLabel('manualTransactionHandling')) {+ if (await bundle.note.hasOwnedLabel('manualTransactionHandling')) {return await execute(ctx, script);}else {@@ -117,7 +117,7 @@ async function getScriptBundle(note, root = true, scriptEnv = null, includedNotereturn;}- if (!root && await note.hasLabel('disableInclusion')) {+ if (!root && await note.hasOwnedLabel('disableInclusion')) {return;}