script api docs

This commit is contained in:
zadam 2023-05-31 14:00:37 +02:00
parent d26a0fae17
commit a9dae7823f
24 changed files with 881 additions and 105 deletions

View file

@ -991,7 +991,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -1904,7 +1904,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -1916,7 +1916,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -1461,7 +1461,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

File diff suppressed because it is too large Load diff

View file

@ -2174,7 +2174,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -267,7 +267,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="becca_entities_boption.js.html">becca/entities/boption.js</a>, <a href="becca_entities_boption.js.html#line24">line 24</a>
<a href="becca_entities_boption.js.html">becca/entities/boption.js</a>, <a href="becca_entities_boption.js.html#line29">line 29</a>
</li></ul></dd>
@ -335,7 +335,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="becca_entities_boption.js.html">becca/entities/boption.js</a>, <a href="becca_entities_boption.js.html#line20">line 20</a>
<a href="becca_entities_boption.js.html">becca/entities/boption.js</a>, <a href="becca_entities_boption.js.html#line25">line 25</a>
</li></ul></dd>
@ -403,7 +403,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="becca_entities_boption.js.html">becca/entities/boption.js</a>, <a href="becca_entities_boption.js.html#line26">line 26</a>
<a href="becca_entities_boption.js.html">becca/entities/boption.js</a>, <a href="becca_entities_boption.js.html#line31">line 31</a>
</li></ul></dd>
@ -471,7 +471,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="becca_entities_boption.js.html">becca/entities/boption.js</a>, <a href="becca_entities_boption.js.html#line22">line 22</a>
<a href="becca_entities_boption.js.html">becca/entities/boption.js</a>, <a href="becca_entities_boption.js.html#line27">line 27</a>
</li></ul></dd>
@ -1319,7 +1319,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -1251,7 +1251,7 @@ This is a low level method, for notes and branches use `note.deleteNote()` and '
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -3254,7 +3254,7 @@ JSON MIME type. See also createNewNote() for more options.
<h4 class="name" id="ensureNoteIsPresentInParent"><span class="type-signature"></span>ensureNoteIsPresentInParent<span class="signature">(noteId, parentNoteId, prefix)</span><span class="type-signature"> &rarr; {void}</span></h4>
<h4 class="name" id="ensureNoteIsPresentInParent"><span class="type-signature"></span>ensureNoteIsPresentInParent<span class="signature">(noteId, parentNoteId, prefix)</span><span class="type-signature"> &rarr; {Object}</span></h4>
@ -3262,7 +3262,7 @@ JSON MIME type. See also createNewNote() for more options.
<div class="description">
If there's no branch between note and parent note, create one. Otherwise, do nothing.
If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch.
</div>
@ -3437,7 +3437,7 @@ JSON MIME type. See also createNewNote() for more options.
</dt>
<dd>
<span class="param-type">void</span>
<span class="param-type">Object</span>
</dd>
@ -7889,7 +7889,7 @@ exists, then we'll use that transaction.
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -212,7 +212,7 @@ module.exports = AbstractBeccaEntity;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -124,7 +124,7 @@ class BAttribute extends AbstractBeccaEntity {
}
if (this.type === 'relation' &amp;&amp; !(this.value in this.becca.notes)) {
throw new Error(`Cannot save relation '${this.name}' of note '${this.noteId}' since it target not existing note '${this.value}'.`);
throw new Error(`Cannot save relation '${this.name}' of note '${this.noteId}' since it targets not existing note '${this.value}'.`);
}
}
@ -276,7 +276,7 @@ module.exports = BAttribute;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -319,7 +319,7 @@ module.exports = BBranch;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -120,7 +120,7 @@ module.exports = BEtapiToken;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -125,7 +125,7 @@ class BNote extends AbstractBeccaEntity {
* @private */
this.parents = [];
/** @type {BNote[]}
* @private*/
* @private */
this.children = [];
/** @type {BAttribute[]}
* @private */
@ -135,11 +135,11 @@ class BNote extends AbstractBeccaEntity {
* @private */
this.__attributeCache = null;
/** @type {BAttribute[]|null}
* @private*/
* @private */
this.inheritableAttributeCache = null;
/** @type {BAttribute[]}
* @private*/
* @private */
this.targetRelations = [];
this.becca.addNote(this.noteId, this);
@ -560,6 +560,20 @@ class BNote extends AbstractBeccaEntity {
*/
hasLabel(name, value) { return this.hasAttribute(LABEL, name, value); }
/**
* @param {string} name - label name
* @returns {boolean} true if label exists (including inherited) and does not have "false" value.
*/
isLabelTruthy(name) {
const label = this.getLabel(name);
if (!label) {
return false;
}
return label &amp;&amp; label.value !== 'false';
}
/**
* @param {string} name - label name
* @param {string} [value] - label value
@ -761,6 +775,21 @@ class BNote extends AbstractBeccaEntity {
return this.hasAttribute('label', 'archived');
}
areAllNotePathsArchived() {
// there's a slight difference between note being itself archived and all its note paths being archived
// - note is archived when it itself has an archived label or inherits it
// - note does not have or inherit archived label, but each note paths contains a note with (non-inheritable)
// archived label
const bestNotePathRecord = this.getSortedNotePathRecords()[0];
if (!bestNotePathRecord) {
throw new Error(`No note path available for note '${this.noteId}'`);
}
return bestNotePathRecord.isArchived;
}
hasInheritableArchivedLabel() {
for (const attr of this.getAttributes()) {
if (attr.name === 'archived' &amp;&amp; attr.type === LABEL &amp;&amp; attr.isInheritable) {
@ -1164,6 +1193,8 @@ class BNote extends AbstractBeccaEntity {
}
/**
* Gives all possible note paths leading to this note. Paths containing search note are ignored (could form cycles)
*
* @returns {string[][]} - array of notePaths (each represented by array of noteIds constituting the particular note path)
*/
getAllNotePaths() {
@ -1171,18 +1202,73 @@ class BNote extends AbstractBeccaEntity {
return [['root']];
}
const notePaths = [];
const parentNotes = this.getParentNotes();
let notePaths = [];
for (const parentNote of this.getParentNotes()) {
for (const parentPath of parentNote.getAllNotePaths()) {
parentPath.push(this.noteId);
notePaths.push(parentPath);
}
if (parentNotes.length === 1) { // optimization for most common case
notePaths = parentNotes[0].getAllNotePaths();
} else {
notePaths = parentNotes.flatMap(parentNote => parentNote.getAllNotePaths());
}
for (const notePath of notePaths) {
notePath.push(this.noteId);
}
return notePaths;
}
/**
* @param {string} [hoistedNoteId='root']
* @return {Array&lt;{isArchived: boolean, isInHoistedSubTree: boolean, notePath: Array&lt;string>, isHidden: boolean}>}
*/
getSortedNotePathRecords(hoistedNoteId = 'root') {
const isHoistedRoot = hoistedNoteId === 'root';
const notePaths = this.getAllNotePaths().map(path => ({
notePath: path,
isInHoistedSubTree: isHoistedRoot || path.includes(hoistedNoteId),
isArchived: path.some(noteId => this.becca.notes[noteId].isArchived),
isHidden: path.includes('_hidden')
}));
notePaths.sort((a, b) => {
if (a.isInHoistedSubTree !== b.isInHoistedSubTree) {
return a.isInHoistedSubTree ? -1 : 1;
} else if (a.isArchived !== b.isArchived) {
return a.isArchived ? 1 : -1;
} else if (a.isHidden !== b.isHidden) {
return a.isHidden ? 1 : -1;
} else {
return a.notePath.length - b.notePath.length;
}
});
return notePaths;
}
/**
* Returns note path considered to be the "best"
*
* @param {string} [hoistedNoteId='root']
* @return {string[]} array of noteIds constituting the particular note path
*/
getBestNotePath(hoistedNoteId = 'root') {
return this.getSortedNotePathRecords(hoistedNoteId)[0]?.notePath;
}
/**
* Returns note path considered to be the "best"
*
* @param {string} [hoistedNoteId='root']
* @return {string} serialized note path (e.g. 'root/a1h315/js725h')
*/
getBestNotePathString(hoistedNoteId = 'root') {
const notePath = this.getBestNotePath(hoistedNoteId);
return notePath?.join("/");
}
/**
* @return boolean - true if there's no non-hidden path, note is not cloned to the visible tree
*/
@ -1196,9 +1282,7 @@ class BNote extends AbstractBeccaEntity {
return false;
} else if (parentNote.noteId === '_hidden') {
continue;
}
if (!parentNote.isHiddenCompletely()) {
} else if (!parentNote.isHiddenCompletely()) {
return false;
}
}
@ -1392,7 +1476,7 @@ class BNote extends AbstractBeccaEntity {
/**
* @param parentNoteId
* @returns {{success: boolean, message: string}}
* @returns {{success: boolean, message: string, branchId: string, notePath: string}}
*/
cloneTo(parentNoteId) {
const cloningService = require("../../services/cloning");
@ -1550,7 +1634,7 @@ module.exports = BNote;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -194,12 +194,14 @@ class BNoteRevision extends AbstractBeccaEntity {
utcDateLastEdited: this.utcDateLastEdited,
utcDateCreated: this.utcDateCreated,
utcDateModified: this.utcDateModified,
content: this.content, // used when retrieving full note revision to frontend
contentLength: this.contentLength
};
}
getPojoToSave() {
const pojo = this.getPojo();
delete pojo.content; // not getting persisted
delete pojo.contentLength; // not getting persisted
if (pojo.isProtected) {
@ -233,7 +235,7 @@ module.exports = BNoteRevision;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -44,6 +44,11 @@ class BOption extends AbstractBeccaEntity {
constructor(row) {
super();
this.updateFromRow(row);
this.becca.options[this.name] = this;
}
updateFromRow(row) {
/** @type {string} */
this.name = row.name;
/** @type {string} */
@ -52,8 +57,6 @@ class BOption extends AbstractBeccaEntity {
this.isSynced = !!row.isSynced;
/** @type {string} */
this.utcDateModified = row.utcDateModified;
this.becca.options[this.name] = this;
}
beforeSaving() {
@ -89,7 +92,7 @@ module.exports = BOption;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -77,7 +77,7 @@ module.exports = BRecentNote;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -56,7 +56,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -1300,7 +1300,7 @@
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -165,13 +165,13 @@ function BackendScriptApi(currentNote, apiParams) {
this.getNoteWithLabel = attributeService.getNoteWithLabel;
/**
* If there's no branch between note and parent note, create one. Otherwise, do nothing.
* If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch.
*
* @method
* @param {string} noteId
* @param {string} parentNoteId
* @param {string} prefix - if branch will be created between note and parent note, set this prefix
* @returns {void}
* @returns {{branch: BBranch|null}}
*/
this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent;
@ -499,11 +499,11 @@ function BackendScriptApi(currentNote, apiParams) {
if (opts.type === 'script' &amp;&amp; !opts.scriptNoteId) { throw new Error("scriptNoteId is mandatory for launchers of type 'script'"); }
if (opts.type === 'customWidget' &amp;&amp; !opts.widgetNoteId) { throw new Error("widgetNoteId is mandatory for launchers of type 'customWidget'"); }
const parentNoteId = !!opts.isVisible ? '_lbVisibleLaunchers' : '_lbAvailableLaunchers';
const parentNoteId = opts.isVisible ? '_lbVisibleLaunchers' : '_lbAvailableLaunchers';
const noteId = 'al_' + opts.id;
const launcherNote =
becca.getNote(opts.id) ||
becca.getNote(noteId) ||
specialNotesService.createLauncher({
noteId: noteId,
parentNoteId: parentNoteId,
@ -542,7 +542,7 @@ function BackendScriptApi(currentNote, apiParams) {
if (opts.icon) {
launcherNote.setLabel('iconClass', `bx ${opts.icon}`);
} else {
launcherNote.removeLabel('keyboardShortcut');
launcherNote.removeLabel('iconClass');
}
return {note: launcherNote};
@ -584,7 +584,7 @@ module.exports = BackendScriptApi;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

View file

@ -245,7 +245,7 @@ function wrap(query, func) {
// in these cases error should be simply ignored.
console.log(e.message);
return null
return null;
}
throw e;
@ -309,7 +309,7 @@ function fillParamList(paramIds, truncate = true) {
}
// doing it manually to avoid this showing up on the sloq query list
const s = stmt(`INSERT INTO param_list VALUES ${paramIds.map(paramId => `(?)`).join(',')}`, paramIds);
const s = stmt(`INSERT INTO param_list VALUES ${paramIds.map(paramId => `(?)`).join(',')}`);
s.run(paramIds);
}
@ -413,7 +413,7 @@ module.exports = {
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.1</a>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a>
</footer>
<script> prettyPrint(); </script>

1
package-lock.json generated
View file

@ -5,7 +5,6 @@
"requires": true,
"packages": {
"": {
"name": "trilium",
"version": "0.60.1-beta",
"hasInstallScript": true,
"license": "AGPL-3.0-only",

View file

@ -1192,7 +1192,7 @@ class BNote extends AbstractBeccaEntity {
/**
* @param {string} [hoistedNoteId='root']
* @return {{isArchived: boolean, isInHoistedSubTree: boolean, notePath: string[], isHidden: boolean}[]}
* @return {Array<{isArchived: boolean, isInHoistedSubTree: boolean, notePath: Array<string>, isHidden: boolean}>}
*/
getSortedNotePathRecords(hoistedNoteId = 'root') {
const isHoistedRoot = hoistedNoteId === 'root';

View file

@ -332,7 +332,7 @@ class FNote {
/**
* @param {string} [hoistedNoteId='root']
* @return {{isArchived: boolean, isInHoistedSubTree: boolean, notePath: string[], isHidden: boolean}[]}
* @return {Array<{isArchived: boolean, isInHoistedSubTree: boolean, notePath: Array<string>, isHidden: boolean}>}
*/
getSortedNotePathRecords(hoistedNoteId = 'root') {
const isHoistedRoot = hoistedNoteId === 'root';