mirror of
https://github.com/zadam/trilium.git
synced 2025-10-29 17:26:38 +01:00
fixed jsdoc script API generation, closes #2313
This commit is contained in:
@@ -40,6 +40,9 @@ const NoteRevision = require("./note_revision.js");
|
||||
const LABEL = 'label';
|
||||
const RELATION = 'relation';
|
||||
|
||||
/**
|
||||
* Trilium's main entity which can represent text note, image, code note, file attachment etc.
|
||||
*/
|
||||
class Note extends AbstractEntity {
|
||||
static get entityName() { return "notes"; }
|
||||
static get primaryKeyName() { return "noteId"; }
|
||||
@@ -73,68 +76,80 @@ class Note extends AbstractEntity {
|
||||
update([noteId, title, type, mime, isProtected, dateCreated, dateModified, utcDateCreated, utcDateModified]) {
|
||||
// ------ Database persisted attributes ------
|
||||
|
||||
/** @param {string} */
|
||||
/** @type {string} */
|
||||
this.noteId = noteId;
|
||||
/** @param {string} */
|
||||
/** @type {string} */
|
||||
this.title = title;
|
||||
/** @param {boolean} */
|
||||
/** @type {boolean} */
|
||||
this.isProtected = !!isProtected;
|
||||
/** @param {string} */
|
||||
/** @type {string} */
|
||||
this.type = type;
|
||||
/** @param {string} */
|
||||
/** @type {string} */
|
||||
this.mime = mime;
|
||||
/** @param {string} */
|
||||
/** @type {string} */
|
||||
this.dateCreated = dateCreated || dateUtils.localNowDateTime();
|
||||
/** @param {string} */
|
||||
/** @type {string} */
|
||||
this.dateModified = dateModified;
|
||||
/** @param {string} */
|
||||
/** @type {string} */
|
||||
this.utcDateCreated = utcDateCreated || dateUtils.utcNowDateTime();
|
||||
/** @param {string} */
|
||||
/** @type {string} */
|
||||
this.utcDateModified = utcDateModified;
|
||||
|
||||
// ------ Derived attributes ------
|
||||
|
||||
/** @param {boolean} */
|
||||
this.isDecrypted = !this.isProtected;
|
||||
/** @type {boolean} */
|
||||
this.isDecrypted = !this.noteId || !this.isProtected;
|
||||
|
||||
this.decrypt();
|
||||
|
||||
/** @param {string|null} */
|
||||
/** @type {string|null} */
|
||||
this.flatTextCache = null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
init() {
|
||||
/** @param {Branch[]} */
|
||||
/** @type {Branch[]} */
|
||||
this.parentBranches = [];
|
||||
/** @param {Note[]} */
|
||||
/** @type {Note[]} */
|
||||
this.parents = [];
|
||||
/** @param {Note[]} */
|
||||
/** @type {Note[]} */
|
||||
this.children = [];
|
||||
/** @param {Attribute[]} */
|
||||
/** @type {Attribute[]} */
|
||||
this.ownedAttributes = [];
|
||||
|
||||
/** @param {Attribute[]|null} */
|
||||
/** @type {Attribute[]|null}
|
||||
* @private */
|
||||
this.__attributeCache = null;
|
||||
/** @param {Attribute[]|null} */
|
||||
/** @type {Attribute[]|null}
|
||||
* @private*/
|
||||
this.inheritableAttributeCache = null;
|
||||
|
||||
/** @param {Attribute[]} */
|
||||
/** @type {Attribute[]} */
|
||||
this.targetRelations = [];
|
||||
|
||||
this.becca.notes[this.noteId] = this;
|
||||
this.becca.addNote(this.noteId, this);
|
||||
|
||||
/** @param {Note[]|null} */
|
||||
/** @type {Note[]|null}
|
||||
* @private */
|
||||
this.ancestorCache = null;
|
||||
|
||||
// following attributes are filled during searching from database
|
||||
|
||||
/** @param {int} size of the content in bytes */
|
||||
/**
|
||||
* size of the content in bytes
|
||||
* @type {int|null}
|
||||
*/
|
||||
this.contentSize = null;
|
||||
/** @param {int} size of the content and note revision contents in bytes */
|
||||
/**
|
||||
* size of the content and note revision contents in bytes
|
||||
* @type {int|null}
|
||||
*/
|
||||
this.noteSize = null;
|
||||
/** @param {int} number of note revisions for this note */
|
||||
/**
|
||||
* number of note revisions for this note
|
||||
* @type {int|null}
|
||||
*/
|
||||
this.revisionCount = null;
|
||||
}
|
||||
|
||||
@@ -144,26 +159,32 @@ class Note extends AbstractEntity {
|
||||
|| protectedSessionService.isProtectedSessionAvailable()
|
||||
}
|
||||
|
||||
/** @returns {Branch[]} */
|
||||
getParentBranches() {
|
||||
return this.parentBranches;
|
||||
}
|
||||
|
||||
/** @returns {Branch[]} */
|
||||
getBranches() {
|
||||
return this.parentBranches;
|
||||
}
|
||||
|
||||
/** @returns {Note[]} */
|
||||
getParentNotes() {
|
||||
return this.parents;
|
||||
}
|
||||
|
||||
/** @returns {Note[]} */
|
||||
getChildNotes() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
/** @returns {boolean} */
|
||||
hasChildren() {
|
||||
return this.children && this.children.length > 0;
|
||||
}
|
||||
|
||||
/** @returns {Branch[]} */
|
||||
getChildBranches() {
|
||||
return this.children.map(childNote => this.becca.getBranchFromChildAndParent(childNote.noteId, this.noteId));
|
||||
}
|
||||
@@ -398,7 +419,7 @@ class Note extends AbstractEntity {
|
||||
return this.__attributeCache;
|
||||
}
|
||||
|
||||
/** @return {Attribute[]} */
|
||||
/** @returns {Attribute[]} */
|
||||
__getInheritableAttributes(path) {
|
||||
if (path.includes(this.noteId)) {
|
||||
return [];
|
||||
@@ -639,7 +660,7 @@ class Note extends AbstractEntity {
|
||||
|
||||
// will sort the parents so that non-search & non-archived are first and archived at the end
|
||||
// this is done so that non-search & non-archived paths are always explored as first when looking for note path
|
||||
resortParents() {
|
||||
sortParents() {
|
||||
this.parentBranches.sort((a, b) =>
|
||||
a.branchId.startsWith('virt-')
|
||||
|| a.parentNote.hasInheritableOwnedArchivedLabel() ? 1 : -1);
|
||||
@@ -749,28 +770,38 @@ class Note extends AbstractEntity {
|
||||
return !!this.targetRelations.find(rel => rel.name === 'template');
|
||||
}
|
||||
|
||||
/** @return {Note[]} */
|
||||
/** @returns {Note[]} */
|
||||
getSubtreeNotesIncludingTemplated() {
|
||||
const arr = [[this]];
|
||||
const set = new Set();
|
||||
|
||||
for (const childNote of this.children) {
|
||||
arr.push(childNote.getSubtreeNotesIncludingTemplated());
|
||||
}
|
||||
function inner(note) {
|
||||
if (set.has(note)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const targetRelation of this.targetRelations) {
|
||||
if (targetRelation.name === 'template') {
|
||||
const note = targetRelation.note;
|
||||
set.add(note);
|
||||
|
||||
if (note) {
|
||||
arr.push(note.getSubtreeNotesIncludingTemplated());
|
||||
for (const childNote of note.children) {
|
||||
inner(childNote);
|
||||
}
|
||||
|
||||
for (const targetRelation of note.targetRelations) {
|
||||
if (targetRelation.name === 'template') {
|
||||
const targetNote = targetRelation.note;
|
||||
|
||||
if (targetNote) {
|
||||
inner(targetNote);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return arr.flat();
|
||||
inner(this);
|
||||
|
||||
return Array.from(set);
|
||||
}
|
||||
|
||||
/** @return {Note[]} */
|
||||
/** @returns {Note[]} */
|
||||
getSubtreeNotes(includeArchived = true) {
|
||||
const noteSet = new Set();
|
||||
|
||||
@@ -791,9 +822,9 @@ class Note extends AbstractEntity {
|
||||
return Array.from(noteSet);
|
||||
}
|
||||
|
||||
/** @return {String[]} */
|
||||
getSubtreeNoteIds() {
|
||||
return this.getSubtreeNotes().map(note => note.noteId);
|
||||
/** @returns {String[]} */
|
||||
getSubtreeNoteIds(includeArchived = true) {
|
||||
return this.getSubtreeNotes(includeArchived).map(note => note.noteId);
|
||||
}
|
||||
|
||||
getDescendantNoteIds() {
|
||||
@@ -848,6 +879,7 @@ class Note extends AbstractEntity {
|
||||
return this.getAttributes().length;
|
||||
}
|
||||
|
||||
/** @returns {Note[]} */
|
||||
getAncestors() {
|
||||
if (!this.ancestorCache) {
|
||||
const noteIds = new Set();
|
||||
@@ -871,11 +903,22 @@ class Note extends AbstractEntity {
|
||||
return this.ancestorCache;
|
||||
}
|
||||
|
||||
/** @returns {boolean} */
|
||||
hasAncestor(ancestorNoteId) {
|
||||
for (const ancestorNote of this.getAncestors()) {
|
||||
if (ancestorNote.noteId === ancestorNoteId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getTargetRelations() {
|
||||
return this.targetRelations;
|
||||
}
|
||||
|
||||
/** @return {Note[]} - returns only notes which are templated, does not include their subtrees
|
||||
/** @returns {Note[]} - returns only notes which are templated, does not include their subtrees
|
||||
* in effect returns notes which are influenced by note's non-inheritable attributes */
|
||||
getTemplatedNotes() {
|
||||
const arr = [this];
|
||||
@@ -1112,10 +1155,14 @@ class Note extends AbstractEntity {
|
||||
}
|
||||
}
|
||||
|
||||
get isDeleted() {
|
||||
return !(this.noteId in this.becca.notes);
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
super.beforeSaving();
|
||||
|
||||
this.becca.notes[this.noteId] = this;
|
||||
this.becca.addNote(this.noteId, this);
|
||||
|
||||
this.dateModified = dateUtils.localNowDateTime();
|
||||
this.utcDateModified = dateUtils.utcNowDateTime();
|
||||
@@ -1164,7 +1211,7 @@ module.exports = Note;
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-sql.html">sql</a></li></ul><h3>Classes</h3><ul><li><a href="ApiToken.html">ApiToken</a></li><li><a href="BackendScriptApi.html">BackendScriptApi</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>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-sql.html">sql</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>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
Reference in New Issue
Block a user