server-ts: Remove unnecessary type comments

This commit is contained in:
Elian Doran 2024-04-17 22:35:38 +03:00
parent 17eda952e4
commit 262e4db0f2
No known key found for this signature in database
8 changed files with 44 additions and 81 deletions

View File

@ -125,9 +125,6 @@ class BAttribute extends AbstractBeccaEntity<BAttribute> {
} }
} }
/**
* @returns {BNote|null}
*/
getNote() { getNote() {
const note = this.becca.getNote(this.noteId); const note = this.becca.getNote(this.noteId);
@ -138,9 +135,6 @@ class BAttribute extends AbstractBeccaEntity<BAttribute> {
return note; return note;
} }
/**
* @returns {BNote|null}
*/
getTargetNote() { getTargetNote() {
if (this.type !== 'relation') { if (this.type !== 'relation') {
throw new Error(`Attribute '${this.attributeId}' is not a relation.`); throw new Error(`Attribute '${this.attributeId}' is not a relation.`);
@ -153,9 +147,6 @@ class BAttribute extends AbstractBeccaEntity<BAttribute> {
return this.becca.getNote(this.value); return this.becca.getNote(this.value);
} }
/**
* @returns {boolean}
*/
isDefinition() { isDefinition() {
return this.type === 'label' && (this.name.startsWith('label:') || this.name.startsWith('relation:')); return this.type === 'label' && (this.name.startsWith('label:') || this.name.startsWith('relation:'));
} }

View File

@ -127,8 +127,6 @@ class BBranch extends AbstractBeccaEntity<BBranch> {
* An example is shared or bookmarked clones - they are created automatically and exist for technical reasons, * An example is shared or bookmarked clones - they are created automatically and exist for technical reasons,
* not as user-intended actions. From user perspective, they don't count as real clones and for the purpose * not as user-intended actions. From user perspective, they don't count as real clones and for the purpose
* of deletion should not act as a clone. * of deletion should not act as a clone.
*
* @returns {boolean}
*/ */
get isWeak() { get isWeak() {
return ['_share', '_lbBookmarks'].includes(this.parentNoteId); return ['_share', '_lbBookmarks'].includes(this.parentNoteId);

View File

@ -167,39 +167,32 @@ class BNote extends AbstractBeccaEntity<BNote> {
return this.isContentAvailable() ? this.title : '[protected]'; return this.isContentAvailable() ? this.title : '[protected]';
} }
/** @returns {BBranch[]} */
getParentBranches() { getParentBranches() {
return this.parentBranches; return this.parentBranches;
} }
/** /**
* Returns <i>strong</i> (as opposed to <i>weak</i>) parent branches. See isWeak for details. * Returns <i>strong</i> (as opposed to <i>weak</i>) parent branches. See isWeak for details.
*
* @returns {BBranch[]}
*/ */
getStrongParentBranches() { getStrongParentBranches() {
return this.getParentBranches().filter(branch => !branch.isWeak); return this.getParentBranches().filter(branch => !branch.isWeak);
} }
/** /**
* @returns {BBranch[]}
* @deprecated use getParentBranches() instead * @deprecated use getParentBranches() instead
*/ */
getBranches() { getBranches() {
return this.parentBranches; return this.parentBranches;
} }
/** @returns {BNote[]} */
getParentNotes() { getParentNotes() {
return this.parents; return this.parents;
} }
/** @returns {BNote[]} */
getChildNotes() { getChildNotes() {
return this.children; return this.children;
} }
/** @returns {boolean} */
hasChildren() { hasChildren() {
return this.children && this.children.length > 0; return this.children && this.children.length > 0;
} }
@ -270,17 +263,17 @@ class BNote extends AbstractBeccaEntity<BNote> {
return this.utcDateModified === null ? null : dayjs.utc(this.utcDateModified); return this.utcDateModified === null ? null : dayjs.utc(this.utcDateModified);
} }
/** @returns {boolean} true if this note is the root of the note tree. Root note has "root" noteId */ /** @returns true if this note is the root of the note tree. Root note has "root" noteId */
isRoot() { isRoot() {
return this.noteId === 'root'; return this.noteId === 'root';
} }
/** @returns {boolean} true if this note is of application/json content type */ /** @returns true if this note is of application/json content type */
isJson() { isJson() {
return this.mime === "application/json"; return this.mime === "application/json";
} }
/** @returns {boolean} true if this note is JavaScript (code or attachment) */ /** @returns true if this note is JavaScript (code or attachment) */
isJavaScript() { isJavaScript() {
return (this.type === "code" || this.type === "file" || this.type === 'launcher') return (this.type === "code" || this.type === "file" || this.type === 'launcher')
&& (this.mime.startsWith("application/javascript") && (this.mime.startsWith("application/javascript")
@ -288,13 +281,13 @@ class BNote extends AbstractBeccaEntity<BNote> {
|| this.mime === "text/javascript"); || this.mime === "text/javascript");
} }
/** @returns {boolean} true if this note is HTML */ /** @returns true if this note is HTML */
isHtml() { isHtml() {
return ["code", "file", "render"].includes(this.type) return ["code", "file", "render"].includes(this.type)
&& this.mime === "text/html"; && this.mime === "text/html";
} }
/** @returns {boolean} true if this note is an image */ /** @returns true if this note is an image */
isImage() { isImage() {
return this.type === 'image' return this.type === 'image'
|| (this.type === 'file' && this.mime?.startsWith('image/')); || (this.type === 'file' && this.mime?.startsWith('image/'));
@ -305,12 +298,12 @@ class BNote extends AbstractBeccaEntity<BNote> {
return this.hasStringContent(); return this.hasStringContent();
} }
/** @returns {boolean} true if the note has string content (not binary) */ /** @returns true if the note has string content (not binary) */
hasStringContent() { hasStringContent() {
return utils.isStringNote(this.type, this.mime); return utils.isStringNote(this.type, this.mime);
} }
/** @returns {string|null} JS script environment - either "frontend" or "backend" */ /** @returns JS script environment - either "frontend" or "backend" */
getScriptEnv() { getScriptEnv() {
if (this.isHtml() || (this.isJavaScript() && this.mime.endsWith('env=frontend'))) { if (this.isHtml() || (this.isJavaScript() && this.mime.endsWith('env=frontend'))) {
return "frontend"; return "frontend";
@ -519,8 +512,8 @@ class BNote extends AbstractBeccaEntity<BNote> {
} }
/** /**
* @param {string} name - label name * @param name - label name
* @returns {BAttribute|null} label if it exists, null otherwise * @returns label if it exists, null otherwise
*/ */
getLabel(name: string): BAttribute | null { getLabel(name: string): BAttribute | null {
return this.getAttribute(LABEL, name); return this.getAttribute(LABEL, name);
@ -681,7 +674,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
* @param type - (optional) attribute type to filter * @param type - (optional) attribute type to filter
* @param name - (optional) attribute name to filter * @param name - (optional) attribute name to filter
* @param value - (optional) attribute value to filter * @param value - (optional) attribute value to filter
* @returns {BAttribute[]} note's "owned" attributes - excluding inherited ones * @returns note's "owned" attributes - excluding inherited ones
*/ */
getOwnedAttributes(type: string | null = null, name: string | null = null, value: string | null = null) { getOwnedAttributes(type: string | null = null, name: string | null = null, value: string | null = null) {
this.__validateTypeName(type, name); this.__validateTypeName(type, name);
@ -704,7 +697,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
} }
/** /**
* @returns {BAttribute} attribute belonging to this specific note (excludes inherited attributes) * @returns attribute belonging to this specific note (excludes inherited attributes)
* *
* This method can be significantly faster than the getAttribute() * This method can be significantly faster than the getAttribute()
*/ */
@ -781,7 +774,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
* - fast searching * - fast searching
* - note similarity evaluation * - note similarity evaluation
* *
* @returns {string} - returns flattened textual representation of note, prefixes and attributes * @returns - returns flattened textual representation of note, prefixes and attributes
*/ */
getFlatText() { getFlatText() {
if (!this.__flatTextCache) { if (!this.__flatTextCache) {
@ -972,7 +965,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
}; };
} }
/** @returns {string[]} - includes the subtree root note as well */ /** @returns includes the subtree root note as well */
getSubtreeNoteIds({includeArchived = true, includeHidden = false, resolveSearch = false} = {}) { getSubtreeNoteIds({includeArchived = true, includeHidden = false, resolveSearch = false} = {}) {
return this.getSubtree({includeArchived, includeHidden, resolveSearch}) return this.getSubtree({includeArchived, includeHidden, resolveSearch})
.notes .notes
@ -1032,7 +1025,6 @@ class BNote extends AbstractBeccaEntity<BNote> {
return this.getOwnedAttributes().length; return this.getOwnedAttributes().length;
} }
/** @returns {BNote[]} */
getAncestors() { getAncestors() {
if (!this.__ancestorCache) { if (!this.__ancestorCache) {
const noteIds = new Set(); const noteIds = new Set();
@ -1076,7 +1068,6 @@ class BNote extends AbstractBeccaEntity<BNote> {
return this.noteId === '_hidden' || this.hasAncestor('_hidden'); return this.noteId === '_hidden' || this.hasAncestor('_hidden');
} }
/** @returns {BAttribute[]} */
getTargetRelations() { getTargetRelations() {
return this.targetRelations; return this.targetRelations;
} }
@ -1118,7 +1109,6 @@ class BNote extends AbstractBeccaEntity<BNote> {
.map(row => new BRevision(row)); .map(row => new BRevision(row));
} }
/** @returns {BAttachment[]} */
getAttachments(opts: AttachmentOpts = {}) { getAttachments(opts: AttachmentOpts = {}) {
opts.includeContentLength = !!opts.includeContentLength; opts.includeContentLength = !!opts.includeContentLength;
// from testing, it looks like calculating length does not make a difference in performance even on large-ish DB // from testing, it looks like calculating length does not make a difference in performance even on large-ish DB
@ -1136,7 +1126,6 @@ class BNote extends AbstractBeccaEntity<BNote> {
.map(row => new BAttachment(row)); .map(row => new BAttachment(row));
} }
/** @returns {BAttachment|null} */
getAttachmentById(attachmentId: string, opts: AttachmentOpts = {}) { getAttachmentById(attachmentId: string, opts: AttachmentOpts = {}) {
opts.includeContentLength = !!opts.includeContentLength; opts.includeContentLength = !!opts.includeContentLength;
@ -1583,10 +1572,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
return !(this.noteId in this.becca.notes) || this.isBeingDeleted; return !(this.noteId in this.becca.notes) || this.isBeingDeleted;
} }
/** saveRevision(): BRevision {
* @returns {BRevision|null}
*/
saveRevision() {
return sql.transactional(() => { return sql.transactional(() => {
let noteContent = this.getContent(); let noteContent = this.getContent();
@ -1633,9 +1619,8 @@ class BNote extends AbstractBeccaEntity<BNote> {
} }
/** /**
* @param {string} matchBy - choose by which property we detect if to update an existing attachment. * @param matchBy - choose by which property we detect if to update an existing attachment.
* Supported values are either 'attachmentId' (default) or 'title' * Supported values are either 'attachmentId' (default) or 'title'
* @returns {BAttachment}
*/ */
saveAttachment({attachmentId, role, mime, title, content, position}: AttachmentRow, matchBy = 'attachmentId') { saveAttachment({attachmentId, role, mime, title, content, position}: AttachmentRow, matchBy = 'attachmentId') {
if (!['attachmentId', 'title'].includes(matchBy)) { if (!['attachmentId', 'title'].includes(matchBy)) {

View File

@ -122,17 +122,14 @@ interface Api {
/** /**
* This is a powerful search method - you can search by attributes and their values, e.g.: * This is a powerful search method - you can search by attributes and their values, e.g.:
* "#dateModified =* MONTH AND #log". See {@link https://github.com/zadam/trilium/wiki/Search} for full documentation for all options * "#dateModified =* MONTH AND #log". See {@link https://github.com/zadam/trilium/wiki/Search} for full documentation for all options
*
* @param {string} query
* @param {Object} [searchParams]
*/ */
searchForNote(query: string, searchParams: SearchParams): BNote | null; searchForNote(query: string, searchParams: SearchParams): BNote | null;
/** /**
* Retrieves notes with given label name & value * Retrieves notes with given label name & value
* *
* @param name - attribute name * @param name - attribute name
* @param value - attribute value * @param value - attribute value
*/ */
getNotesWithLabel(name: string, value?: string): BNote[]; getNotesWithLabel(name: string, value?: string): BNote[];

View File

@ -69,7 +69,7 @@ class ConsistencyChecks {
childToParents[childNoteId].push(parentNoteId); childToParents[childNoteId].push(parentNoteId);
} }
/** @returns {boolean} true if cycle was found and we should try again */ /** @returns true if cycle was found and we should try again */
const checkTreeCycle = (noteId: string, path: string[]) => { const checkTreeCycle = (noteId: string, path: string[]) => {
if (noteId === 'root') { if (noteId === 'root') {
return false; return false;

View File

@ -17,8 +17,7 @@ type EventListener = (data: any) => void;
const eventListeners: Record<string, EventListener[]> = {}; const eventListeners: Record<string, EventListener[]> = {};
/** /**
* @param {string|string[]}eventTypes - can be either single event or an array of events * @param eventTypes - can be either single event or an array of events
* @param listener
*/ */
function subscribe(eventTypes: EventType, listener: EventListener) { function subscribe(eventTypes: EventType, listener: EventListener) {
if (!Array.isArray(eventTypes)) { if (!Array.isArray(eventTypes)) {

View File

@ -323,9 +323,9 @@ export = {
* Get single value from the given query - first column from first returned row. * Get single value from the given query - first column from first returned row.
* *
* @method * @method
* @param {string} query - SQL query with ? used as parameter placeholder * @param query - SQL query with ? used as parameter placeholder
* @param {object[]} [params] - array of params if needed * @param params - array of params if needed
* @returns [object] - single value * @returns single value
*/ */
getValue, getValue,
@ -333,9 +333,9 @@ export = {
* Get first returned row. * Get first returned row.
* *
* @method * @method
* @param {string} query - SQL query with ? used as parameter placeholder * @param query - SQL query with ? used as parameter placeholder
* @param {object[]} [params] - array of params if needed * @param params - array of params if needed
* @returns {object} - map of column name to column value * @returns - map of column name to column value
*/ */
getRow, getRow,
getRowOrNull, getRowOrNull,
@ -344,9 +344,9 @@ export = {
* Get all returned rows. * Get all returned rows.
* *
* @method * @method
* @param {string} query - SQL query with ? used as parameter placeholder * @param query - SQL query with ? used as parameter placeholder
* @param {object[]} [params] - array of params if needed * @param params - array of params if needed
* @returns {object[]} - array of all rows, each row is a map of column name to column value * @returns - array of all rows, each row is a map of column name to column value
*/ */
getRows, getRows,
getRawRows, getRawRows,
@ -357,9 +357,9 @@ export = {
* Get a map of first column mapping to second column. * Get a map of first column mapping to second column.
* *
* @method * @method
* @param {string} query - SQL query with ? used as parameter placeholder * @param query - SQL query with ? used as parameter placeholder
* @param {object[]} [params] - array of params if needed * @param params - array of params if needed
* @returns {object} - map of first column to second column * @returns - map of first column to second column
*/ */
getMap, getMap,
@ -367,9 +367,9 @@ export = {
* Get a first column in an array. * Get a first column in an array.
* *
* @method * @method
* @param {string} query - SQL query with ? used as parameter placeholder * @param query - SQL query with ? used as parameter placeholder
* @param {object[]} [params] - array of params if needed * @param params - array of params if needed
* @returns {object[]} - array of first column of all returned rows * @returns array of first column of all returned rows
*/ */
getColumn, getColumn,
@ -377,8 +377,8 @@ export = {
* Execute SQL * Execute SQL
* *
* @method * @method
* @param {string} query - SQL query with ? used as parameter placeholder * @param query - SQL query with ? used as parameter placeholder
* @param {object[]} [params] - array of params if needed * @param params - array of params if needed
*/ */
execute, execute,
executeMany, executeMany,

View File

@ -69,35 +69,29 @@ class SNote extends AbstractShacaEntity {
return this.children.map(childNote => this.shaca.getBranchFromChildAndParent(childNote.noteId, this.noteId)); return this.children.map(childNote => this.shaca.getBranchFromChildAndParent(childNote.noteId, this.noteId));
} }
/** @returns {SBranch[]} */
getVisibleChildBranches() { getVisibleChildBranches() {
return this.getChildBranches() return this.getChildBranches()
.filter(branch => !branch.isHidden .filter(branch => !branch.isHidden
&& !branch.getNote().isLabelTruthy('shareHiddenFromTree')); && !branch.getNote().isLabelTruthy('shareHiddenFromTree'));
} }
/** @returns {SNote[]} */
getParentNotes() { getParentNotes() {
return this.parents; return this.parents;
} }
/** @returns {SNote[]} */
getChildNotes() { getChildNotes() {
return this.children; return this.children;
} }
/** @returns {SNote[]} */
getVisibleChildNotes() { getVisibleChildNotes() {
return this.getVisibleChildBranches() return this.getVisibleChildBranches()
.map(branch => branch.getNote()); .map(branch => branch.getNote());
} }
/** @returns {boolean} */
hasChildren() { hasChildren() {
return this.children && this.children.length > 0; return this.children && this.children.length > 0;
} }
/** @returns {boolean} */
hasVisibleChildren() { hasVisibleChildren() {
return this.getVisibleChildNotes().length > 0; return this.getVisibleChildNotes().length > 0;
} }
@ -250,7 +244,6 @@ class SNote extends AbstractShacaEntity {
return !!this.getAttributes().find(attr => attr.type === type && attr.name === name); return !!this.getAttributes().find(attr => attr.type === type && attr.name === name);
} }
/** @returns {SNote|null} */
getRelationTarget(name: string) { getRelationTarget(name: string) {
const relation = this.getAttributes().find(attr => attr.type === 'relation' && attr.name === name); const relation = this.getAttributes().find(attr => attr.type === 'relation' && attr.name === name);
@ -265,7 +258,7 @@ class SNote extends AbstractShacaEntity {
/** /**
* @param name - label name * @param name - label name
* @returns {boolean} true if label exists (including inherited) and does not have "false" value. * @returns true if label exists (including inherited) and does not have "false" value.
*/ */
isLabelTruthy(name: string) { isLabelTruthy(name: string) {
const label = this.getLabel(name); const label = this.getLabel(name);
@ -321,25 +314,25 @@ class SNote extends AbstractShacaEntity {
/** /**
* @param name - label name * @param name - label name
* @returns {string|null} label value if label exists, null otherwise * @returns label value if label exists, null otherwise
*/ */
getLabelValue(name: string) { return this.getAttributeValue(LABEL, name); } getLabelValue(name: string) { return this.getAttributeValue(LABEL, name); }
/** /**
* @param name - label name * @param name - label name
* @returns {string|null} label value if label exists, null otherwise * @returns label value if label exists, null otherwise
*/ */
getOwnedLabelValue(name: string) { return this.getOwnedAttributeValue(LABEL, name); } getOwnedLabelValue(name: string) { return this.getOwnedAttributeValue(LABEL, name); }
/** /**
* @param name - relation name * @param name - relation name
* @returns {string|null} relation value if relation exists, null otherwise * @returns relation value if relation exists, null otherwise
*/ */
getRelationValue(name: string) { return this.getAttributeValue(RELATION, name); } getRelationValue(name: string) { return this.getAttributeValue(RELATION, name); }
/** /**
* @param name - relation name * @param name - relation name
* @returns {string|null} relation value if relation exists, null otherwise * @returns relation value if relation exists, null otherwise
*/ */
getOwnedRelationValue(name: string) { return this.getOwnedAttributeValue(RELATION, name); } getOwnedRelationValue(name: string) { return this.getOwnedAttributeValue(RELATION, name); }
@ -367,7 +360,7 @@ class SNote extends AbstractShacaEntity {
/** /**
* @param type - attribute type (label, relation, etc.) * @param type - attribute type (label, relation, etc.)
* @param name - attribute name * @param name - attribute name
* @returns {string|null} attribute value of the given type and name or null if no such attribute exists. * @returns attribute value of the given type and name or null if no such attribute exists.
*/ */
getAttributeValue(type: string, name: string) { getAttributeValue(type: string, name: string) {
const attr = this.getAttribute(type, name); const attr = this.getAttribute(type, name);
@ -412,7 +405,7 @@ class SNote extends AbstractShacaEntity {
/** /**
* @param name - label name to filter * @param name - label name to filter
* @returns {string[]} all note's label values, excluding inherited ones * @returns all note's label values, excluding inherited ones
*/ */
getOwnedLabelValues(name: string) { getOwnedLabelValues(name: string) {
return this.getOwnedAttributes(LABEL, name).map(l => l.value); return this.getOwnedAttributes(LABEL, name).map(l => l.value);