rename froca entities to have F-prefix, #3476

This commit is contained in:
zadam 2023-01-03 13:35:10 +01:00
parent 957640f163
commit 977a47bc27
14 changed files with 91 additions and 96 deletions

View File

@ -140,7 +140,7 @@ class NoteContext extends Component {
return resolvedNotePath;
}
/** @property {NoteShort} */
/** @property {FNote} */
get note() {
if (!this.noteId || !(this.noteId in froca.notes)) {
return null;
@ -154,7 +154,7 @@ class NoteContext extends Component {
return this.notePath ? this.notePath.split('/') : [];
}
/** @returns {NoteComplement} */
/** @returns {FNoteComplement} */
async getNoteComplement() {
if (!this.noteId) {
return null;

View File

@ -181,7 +181,7 @@ export default class TabManager extends Component {
return activeContext ? activeContext.notePath : null;
}
/** @returns {NoteShort} */
/** @returns {FNote} */
getActiveContextNote() {
const activeContext = this.getActiveContext();
return activeContext ? activeContext.note : null;

View File

@ -4,7 +4,7 @@ import promotedAttributeDefinitionParser from '../services/promoted_attribute_de
* Attribute is an abstract concept which has two real uses - label (key - value pair)
* and relation (representing named relationship between source and target note)
*/
class Attribute {
class FAttribute {
constructor(froca, row) {
this.froca = froca;
@ -28,12 +28,12 @@ class Attribute {
this.isInheritable = !!row.isInheritable;
}
/** @returns {NoteShort} */
/** @returns {FNote} */
getNote() {
return this.froca.notes[this.noteId];
}
/** @returns {Promise<NoteShort>} */
/** @returns {Promise<FNote>} */
async getTargetNote() {
const targetNoteId = this.targetNoteId;
@ -42,7 +42,7 @@ class Attribute {
get targetNoteId() { // alias
if (this.type !== 'relation') {
throw new Error(`Attribute ${this.attributeId} is not a relation`);
throw new Error(`FAttribute ${this.attributeId} is not a relation`);
}
return this.value;
@ -53,7 +53,7 @@ class Attribute {
}
get toString() {
return `Attribute(attributeId=${this.attributeId}, type=${this.type}, name=${this.name}, value=${this.value})`;
return `FAttribute(attributeId=${this.attributeId}, type=${this.type}, name=${this.name}, value=${this.value})`;
}
isDefinition() {
@ -76,4 +76,4 @@ class Attribute {
}
}
export default Attribute;
export default FAttribute;

View File

@ -2,7 +2,7 @@
* Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple
* parents.
*/
class Branch {
class FBranch {
constructor(froca, row) {
this.froca = froca;
@ -29,17 +29,17 @@ class Branch {
this.fromSearchNote = !!row.fromSearchNote;
}
/** @returns {NoteShort} */
/** @returns {FNote} */
async getNote() {
return this.froca.getNote(this.noteId);
}
/** @returns {NoteShort} */
/** @returns {FNote} */
getNoteFromCache() {
return this.froca.getNoteFromCache(this.noteId);
}
/** @returns {NoteShort} */
/** @returns {FNote} */
async getParentNote() {
return this.froca.getNote(this.parentNoteId);
}
@ -50,7 +50,7 @@ class Branch {
}
get toString() {
return `Branch(branchId=${this.branchId})`;
return `FBranch(branchId=${this.branchId})`;
}
get pojo() {
@ -60,4 +60,4 @@ class Branch {
}
}
export default Branch;
export default FBranch;

View File

@ -26,12 +26,7 @@ const NOTE_TYPE_ICONS = {
"contentWidget": "bx bxs-widget"
};
/**
* FIXME: since there's no "full note" anymore we can rename this to Note
*
* This note's representation is used in note tree and is kept in Froca.
*/
class NoteShort {
class FNote {
/**
* @param {Froca} froca
* @param {Object.<string, Object>} row
@ -153,7 +148,7 @@ class NoteShort {
}
/**
* @returns {Branch[]}
* @returns {FBranch[]}
*/
getParentBranches() {
const branchIds = Object.values(this.parentToBranch);
@ -162,7 +157,7 @@ class NoteShort {
}
/**
* @returns {Branch[]}
* @returns {FBranch[]}
* @deprecated use getParentBranches() instead
*/
getBranches() {
@ -174,7 +169,7 @@ class NoteShort {
return this.children.length > 0;
}
/** @returns {Branch[]} */
/** @returns {FBranch[]} */
getChildBranches() {
// don't use Object.values() to guarantee order
const branchIds = this.children.map(childNoteId => this.childToBranch[childNoteId]);
@ -187,7 +182,7 @@ class NoteShort {
return this.parents;
}
/** @returns {NoteShort[]} */
/** @returns {FNote[]} */
getParentNotes() {
return this.froca.getNotesFromCache(this.parents);
}
@ -217,7 +212,7 @@ class NoteShort {
return this.children;
}
/** @returns {Promise<NoteShort[]>} */
/** @returns {Promise<FNote[]>} */
async getChildNotes() {
return await this.froca.getNotes(this.children);
}
@ -225,7 +220,7 @@ class NoteShort {
/**
* @param {string} [type] - (optional) attribute type to filter
* @param {string} [name] - (optional) attribute name to filter
* @returns {Attribute[]} all note's attributes, including inherited ones
* @returns {FAttribute[]} all note's attributes, including inherited ones
*/
getOwnedAttributes(type, name) {
const attrs = this.attributes
@ -238,7 +233,7 @@ class NoteShort {
/**
* @param {string} [type] - (optional) attribute type to filter
* @param {string} [name] - (optional) attribute name to filter
* @returns {Attribute[]} all note's attributes, including inherited ones
* @returns {FAttribute[]} all note's attributes, including inherited ones
*/
getAttributes(type, name) {
return this.__filterAttrs(this.__getCachedAttributes([]), type, name);
@ -399,7 +394,7 @@ class NoteShort {
/**
* @param {string} [name] - label name to filter
* @returns {Attribute[]} all note's labels (attributes with type label), including inherited ones
* @returns {FAttribute[]} all note's labels (attributes with type label), including inherited ones
*/
getOwnedLabels(name) {
return this.getOwnedAttributes(LABEL, name);
@ -407,7 +402,7 @@ class NoteShort {
/**
* @param {string} [name] - label name to filter
* @returns {Attribute[]} all note's labels (attributes with type label), including inherited ones
* @returns {FAttribute[]} all note's labels (attributes with type label), including inherited ones
*/
getLabels(name) {
return this.getAttributes(LABEL, name);
@ -480,7 +475,7 @@ class NoteShort {
/**
* @param {string} [name] - relation name to filter
* @returns {Attribute[]} all note's relations (attributes with type relation), including inherited ones
* @returns {FAttribute[]} all note's relations (attributes with type relation), including inherited ones
*/
getOwnedRelations(name) {
return this.getOwnedAttributes(RELATION, name);
@ -488,7 +483,7 @@ class NoteShort {
/**
* @param {string} [name] - relation name to filter
* @returns {Attribute[]} all note's relations (attributes with type relation), including inherited ones
* @returns {FAttribute[]} all note's relations (attributes with type relation), including inherited ones
*/
getRelations(name) {
return this.getAttributes(RELATION, name);
@ -515,7 +510,7 @@ class NoteShort {
/**
* @param {string} type - attribute type (label, relation, etc.)
* @param {string} name - attribute name
* @returns {Attribute} attribute of given type and name. If there's more such attributes, first is returned. Returns null if there's no such attribute belonging to this note.
* @returns {FAttribute} attribute of given type and name. If there's more such attributes, first is returned. Returns null if there's no such attribute belonging to this note.
*/
getOwnedAttribute(type, name) {
const attributes = this.getOwnedAttributes(type, name);
@ -526,7 +521,7 @@ class NoteShort {
/**
* @param {string} type - attribute type (label, relation, etc.)
* @param {string} name - attribute name
* @returns {Attribute} attribute of given type and name. If there's more such attributes, first is returned. Returns null if there's no such attribute belonging to this note.
* @returns {FAttribute} attribute of given type and name. If there's more such attributes, first is returned. Returns null if there's no such attribute belonging to this note.
*/
getAttribute(type, name) {
const attributes = this.getAttributes(type, name);
@ -582,25 +577,25 @@ class NoteShort {
/**
* @param {string} name - label name
* @returns {Attribute} label if it exists, null otherwise
* @returns {FAttribute} label if it exists, null otherwise
*/
getOwnedLabel(name) { return this.getOwnedAttribute(LABEL, name); }
/**
* @param {string} name - label name
* @returns {Attribute} label if it exists, null otherwise
* @returns {FAttribute} label if it exists, null otherwise
*/
getLabel(name) { return this.getAttribute(LABEL, name); }
/**
* @param {string} name - relation name
* @returns {Attribute} relation if it exists, null otherwise
* @returns {FAttribute} relation if it exists, null otherwise
*/
getOwnedRelation(name) { return this.getOwnedAttribute(RELATION, name); }
/**
* @param {string} name - relation name
* @returns {Attribute} relation if it exists, null otherwise
* @returns {FAttribute} relation if it exists, null otherwise
*/
getRelation(name) { return this.getAttribute(RELATION, name); }
@ -630,7 +625,7 @@ class NoteShort {
/**
* @param {string} name
* @returns {Promise<NoteShort>|null} target note of the relation or null (if target is empty or note was not found)
* @returns {Promise<FNote>|null} target note of the relation or null (if target is empty or note was not found)
*/
async getRelationTarget(name) {
const targets = await this.getRelationTargets(name);
@ -640,7 +635,7 @@ class NoteShort {
/**
* @param {string} [name] - relation name to filter
* @returns {Promise<NoteShort[]>}
* @returns {Promise<FNote[]>}
*/
async getRelationTargets(name) {
const relations = this.getRelations(name);
@ -654,7 +649,7 @@ class NoteShort {
}
/**
* @returns {NoteShort[]}
* @returns {FNote[]}
*/
getTemplateNotes() {
const relations = this.getRelations('template');
@ -722,7 +717,7 @@ class NoteShort {
/**
* Get relations which target this note
*
* @returns {Attribute[]}
* @returns {FAttribute[]}
*/
getTargetRelations() {
return this.targetRelations
@ -732,7 +727,7 @@ class NoteShort {
/**
* Get relations which target this note
*
* @returns {NoteShort[]}
* @returns {FNote[]}
*/
async getTargetRelationSourceNotes() {
const targetRelations = this.getTargetRelations();
@ -743,7 +738,7 @@ class NoteShort {
/**
* Return note complement which is most importantly note's content
*
* @return {Promise<NoteComplement>}
* @return {Promise<FNoteComplement>}
*/
async getNoteComplement() {
return await this.froca.getNoteComplement(this.noteId);
@ -857,4 +852,4 @@ class NoteShort {
}
}
export default NoteShort;
export default FNote;

View File

@ -1,7 +1,7 @@
/**
* Complements the NoteShort with the main note content and other extra attributes
* Complements the FNote with the main note content and other extra attributes
*/
class NoteComplement {
class FNoteComplement {
constructor(row) {
/** @type {string} */
this.noteId = row.noteId;
@ -37,4 +37,4 @@ class NoteComplement {
}
}
export default NoteComplement;
export default FNoteComplement;

View File

@ -2,19 +2,19 @@ import froca from "./froca.js";
import server from "./server.js";
import ws from "./ws.js";
/** @returns {NoteShort} */
/** @returns {FNote} */
async function getInboxNote() {
const note = await server.get(`special-notes/inbox/${dayjs().format("YYYY-MM-DD")}`, "date-note");
return await froca.getNote(note.noteId);
}
/** @returns {NoteShort} */
/** @returns {FNote} */
async function getTodayNote() {
return await getDayNote(dayjs().format("YYYY-MM-DD"));
}
/** @returns {NoteShort} */
/** @returns {FNote} */
async function getDayNote(date) {
const note = await server.get(`special-notes/days/${date}`, "date-note");
@ -23,7 +23,7 @@ async function getDayNote(date) {
return await froca.getNote(note.noteId);
}
/** @returns {NoteShort} */
/** @returns {FNote} */
async function getWeekNote(date) {
const note = await server.get(`special-notes/weeks/${date}`, "date-note");
@ -32,7 +32,7 @@ async function getWeekNote(date) {
return await froca.getNote(note.noteId);
}
/** @returns {NoteShort} */
/** @returns {FNote} */
async function getMonthNote(month) {
const note = await server.get(`special-notes/months/${month}`, "date-note");
@ -41,7 +41,7 @@ async function getMonthNote(month) {
return await froca.getNote(note.noteId);
}
/** @returns {NoteShort} */
/** @returns {FNote} */
async function getYearNote(year) {
const note = await server.get(`special-notes/years/${year}`, "date-note");
@ -50,7 +50,7 @@ async function getYearNote(year) {
return await froca.getNote(note.noteId);
}
/** @returns {NoteShort} */
/** @returns {FNote} */
async function createSqlConsole() {
const note = await server.post('special-notes/sql-console');
@ -59,7 +59,7 @@ async function createSqlConsole() {
return await froca.getNote(note.noteId);
}
/** @returns {NoteShort} */
/** @returns {FNote} */
async function createSearchNote(opts = {}) {
const note = await server.post('special-notes/search-note', opts);

View File

@ -1,9 +1,9 @@
import Branch from "../entities/branch.js";
import NoteShort from "../entities/note_short.js";
import Attribute from "../entities/attribute.js";
import FBranch from "../entities/fbranch.js";
import FNote from "../entities/fnote.js";
import FAttribute from "../entities/fattribute.js";
import server from "./server.js";
import appContext from "../components/app_context.js";
import NoteComplement from "../entities/note_complement.js";
import FNoteComplement from "../entities/fnote_complement.js";
/**
* Froca (FROntend CAche) keeps a read only cache of note tree structure in frontend's memory.
@ -25,16 +25,16 @@ class Froca {
// clear the cache only directly before adding new content which is important for e.g. switching to protected session
/** @type {Object.<string, NoteShort>} */
/** @type {Object.<string, FNote>} */
this.notes = {};
/** @type {Object.<string, Branch>} */
/** @type {Object.<string, FBranch>} */
this.branches = {};
/** @type {Object.<string, Attribute>} */
/** @type {Object.<string, FAttribute>} */
this.attributes = {};
/** @type {Object.<string, Promise<NoteComplement>>} */
/** @type {Object.<string, Promise<FNoteComplement>>} */
this.noteComplementPromises = {};
this.addResp(resp);
@ -103,12 +103,12 @@ class Froca {
});
}
else {
this.notes[noteId] = new NoteShort(this, noteRow);
this.notes[noteId] = new FNote(this, noteRow);
}
}
for (const branchRow of branchRows) {
const branch = new Branch(this, branchRow);
const branch = new FBranch(this, branchRow);
this.branches[branch.branchId] = branch;
@ -130,7 +130,7 @@ class Froca {
for (const attributeRow of attributeRows) {
const {attributeId} = attributeRow;
this.attributes[attributeId] = new Attribute(this, attributeRow);
this.attributes[attributeId] = new FAttribute(this, attributeRow);
const note = this.notes[attributeRow.noteId];
@ -212,7 +212,7 @@ class Froca {
return {error};
}
/** @returns {NoteShort[]} */
/** @returns {FNote[]} */
getNotesFromCache(noteIds, silentNotFoundError = false) {
return noteIds.map(noteId => {
if (!this.notes[noteId] && !silentNotFoundError) {
@ -226,7 +226,7 @@ class Froca {
}).filter(note => !!note);
}
/** @returns {Promise<NoteShort[]>} */
/** @returns {Promise<FNote[]>} */
async getNotes(noteIds, silentNotFoundError = false) {
noteIds = Array.from(new Set(noteIds)); // make unique
const missingNoteIds = noteIds.filter(noteId => !this.notes[noteId]);
@ -251,7 +251,7 @@ class Froca {
return notes.length === 1;
}
/** @returns {Promise<NoteShort>} */
/** @returns {Promise<FNote>} */
async getNote(noteId, silentNotFoundError = false) {
if (noteId === 'none') {
console.trace(`No 'none' note.`);
@ -265,7 +265,7 @@ class Froca {
return (await this.getNotes([noteId], silentNotFoundError))[0];
}
/** @returns {Note|null} */
/** @returns {FNote|null} */
getNoteFromCache(noteId) {
if (!noteId) {
throw new Error("Empty noteId");
@ -274,14 +274,14 @@ class Froca {
return this.notes[noteId];
}
/** @returns {Branch[]} */
/** @returns {FBranch[]} */
getBranches(branchIds, silentNotFoundError = false) {
return branchIds
.map(branchId => this.getBranch(branchId, silentNotFoundError))
.filter(b => !!b);
}
/** @returns {Branch} */
/** @returns {FBranch} */
getBranch(branchId, silentNotFoundError = false) {
if (!(branchId in this.branches)) {
if (!silentNotFoundError) {
@ -310,12 +310,12 @@ class Froca {
}
/**
* @return {Promise<NoteComplement>}
* @return {Promise<FNoteComplement>}
*/
async getNoteComplement(noteId) {
if (!this.noteComplementPromises[noteId]) {
this.noteComplementPromises[noteId] = server.get(`notes/${noteId}`)
.then(row => new NoteComplement(row))
.then(row => new FNoteComplement(row))
.catch(e => console.error(`Cannot get note complement for note '${noteId}'`));
// we don't want to keep large payloads forever in memory so we clean that up quite quickly

View File

@ -3,8 +3,8 @@ import froca from "./froca.js";
import utils from "./utils.js";
import options from "./options.js";
import noteAttributeCache from "./note_attribute_cache.js";
import Branch from "../entities/branch.js";
import Attribute from "../entities/attribute.js";
import FBranch from "../entities/fbranch.js";
import FAttribute from "../entities/fattribute.js";
async function processEntityChanges(entityChanges) {
const loadResults = new LoadResults(entityChanges);
@ -145,7 +145,7 @@ function processBranchChange(loadResults, ec) {
branch.update(ec.entity);
}
else if (childNote || parentNote) {
froca.branches[ec.entityId] = branch = new Branch(froca, ec.entity);
froca.branches[ec.entityId] = branch = new FBranch(froca, ec.entity);
}
if (childNote) {
@ -218,7 +218,7 @@ function processAttributeChange(loadResults, ec) {
if (attribute) {
attribute.update(ec.entity);
} else if (sourceNote || targetNote) {
attribute = new Attribute(froca, ec.entity);
attribute = new FAttribute(froca, ec.entity);
froca.attributes[attribute.attributeId] = attribute;

View File

@ -208,7 +208,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
*
* @method
* @param {string} searchString
* @returns {Promise<NoteShort[]>}
* @returns {Promise<FNote[]>}
*/
this.searchForNotes = async searchString => {
return await searchService.searchForNotes(searchString);
@ -220,7 +220,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
*
* @method
* @param {string} searchString
* @returns {Promise<NoteShort|null>}
* @returns {Promise<FNote|null>}
*/
this.searchForNote = async searchString => {
const notes = await this.searchForNotes(searchString);
@ -232,7 +232,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
* Returns note by given noteId. If note is missing from cache, it's loaded.
**
* @param {string} noteId
* @return {Promise<NoteShort>}
* @return {Promise<FNote>}
*/
this.getNote = async noteId => await froca.getNote(noteId);
@ -244,7 +244,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
*
* @param {string[]} noteIds
* @param {boolean} [silentNotFoundError] - don't report error if the note is not found
* @return {Promise<NoteShort[]>}
* @return {Promise<FNote[]>}
*/
this.getNotes = async (noteIds, silentNotFoundError = false) => await froca.getNotes(noteIds, silentNotFoundError);
@ -355,7 +355,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
/**
* @method
* @deprecated use getActiveContextNote() instead
* @returns {NoteShort} active note (loaded into right pane)
* @returns {FNote} active note (loaded into right pane)
*/
this.getActiveTabNote = () => {
console.warn("api.getActiveTabNote() is deprecated, use getActiveContextNote() instead.");
@ -365,7 +365,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
/**
* @method
* @returns {NoteShort} active note (loaded into right pane)
* @returns {FNote} active note (loaded into right pane)
*/
this.getActiveContextNote = () => appContext.tabManager.getActiveContextNote();
@ -471,7 +471,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
* Returns date-note for today. If it doesn't exist, it is automatically created.
*
* @method
* @return {Promise<NoteShort>}
* @return {Promise<FNote>}
*/
this.getTodayNote = dateNotesService.getTodayNote;
@ -480,7 +480,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
*
* @method
* @param {string} date - e.g. "2019-04-29"
* @return {Promise<NoteShort>}
* @return {Promise<FNote>}
* @deprecated use getDayNote instead
*/
this.getDateNote = dateNotesService.getDayNote;
@ -490,7 +490,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
*
* @method
* @param {string} date - e.g. "2019-04-29"
* @return {Promise<NoteShort>}
* @return {Promise<FNote>}
*/
this.getDayNote = dateNotesService.getDayNote;
@ -499,7 +499,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
*
* @method
* @param {string} date - e.g. "2019-04-29"
* @return {Promise<NoteShort>}
* @return {Promise<FNote>}
*/
this.getWeekNote = dateNotesService.getWeekNote;
@ -508,7 +508,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
*
* @method
* @param {string} month - e.g. "2019-04"
* @return {Promise<NoteShort>}
* @return {Promise<FNote>}
*/
this.getMonthNote = dateNotesService.getMonthNote;
@ -517,7 +517,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
*
* @method
* @param {string} year - e.g. "2019"
* @return {Promise<NoteShort>}
* @return {Promise<FNote>}
*/
this.getYearNote = dateNotesService.getYearNote;

View File

@ -65,7 +65,7 @@ export default class LoadResults {
this.attributes.push({attributeId, componentId});
}
/** @returns {Attribute[]} */
/** @returns {FAttribute[]} */
getAttributes(componentId = 'none') {
return this.attributes
.filter(row => row.componentId !== componentId)

View File

@ -8,7 +8,7 @@ export default class AbstractLauncher extends OnClickButtonWidget {
this.class("launcher-button");
/** @type {NoteShort} */
/** @type {FNote} */
this.launcherNote = launcherNote;
for (const label of launcherNote.getOwnedLabels('keyboardShortcut')) {

View File

@ -641,7 +641,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
}
/**
* @param {NoteShort} parentNote
* @param {FNote} parentNote
*/
prepareChildren(parentNote) {
utils.assertArguments(parentNote);
@ -704,7 +704,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
}
/**
* @param {Branch} branch
* @param {FBranch} branch
* @param {boolean} forceLazy
*/
prepareNode(branch, forceLazy = false) {

View File

@ -12,7 +12,7 @@ export default class TypeWidget extends NoteContextAwareWidget {
}
/**
* @param {NoteShort} note
* @param {FNote} note
*/
async doRefresh(note) {}