mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 17:55:52 +01:00
ETAPI auth, spec improvements etc.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
const sql = require("../services/sql.js");
|
||||
const sql = require("../services/sql");
|
||||
const NoteSet = require("../services/search/note_set");
|
||||
const EtapiToken = require("./entities/etapi_token");
|
||||
|
||||
/**
|
||||
* Becca is a backend cache of all notes, branches and attributes. There's a similar frontend cache Froca.
|
||||
@@ -24,6 +25,8 @@ class Becca {
|
||||
this.attributeIndex = {};
|
||||
/** @type {Object.<String, Option>} */
|
||||
this.options = {};
|
||||
/** @type {Object.<String, EtapiToken>} */
|
||||
this.etapiTokens = {};
|
||||
|
||||
this.loaded = false;
|
||||
}
|
||||
@@ -64,10 +67,12 @@ class Becca {
|
||||
this.dirtyNoteSetCache();
|
||||
}
|
||||
|
||||
/** @returns {Note|null} */
|
||||
getNote(noteId) {
|
||||
return this.notes[noteId];
|
||||
}
|
||||
|
||||
/** @returns {Note[]} */
|
||||
getNotes(noteIds, ignoreMissing = false) {
|
||||
const filteredNotes = [];
|
||||
|
||||
@@ -88,29 +93,44 @@ class Becca {
|
||||
return filteredNotes;
|
||||
}
|
||||
|
||||
/** @returns {Branch|null} */
|
||||
getBranch(branchId) {
|
||||
return this.branches[branchId];
|
||||
}
|
||||
|
||||
/** @returns {Attribute|null} */
|
||||
getAttribute(attributeId) {
|
||||
return this.attributes[attributeId];
|
||||
}
|
||||
|
||||
/** @returns {Branch|null} */
|
||||
getBranchFromChildAndParent(childNoteId, parentNoteId) {
|
||||
return this.childParentToBranch[`${childNoteId}-${parentNoteId}`];
|
||||
}
|
||||
|
||||
/** @returns {NoteRevision|null} */
|
||||
getNoteRevision(noteRevisionId) {
|
||||
const row = sql.getRow("SELECT * FROM note_revisions WHERE noteRevisionId = ?", [noteRevisionId]);
|
||||
|
||||
const NoteRevision = require("./entities/note_revision.js"); // avoiding circular dependency problems
|
||||
const NoteRevision = require("./entities/note_revision"); // avoiding circular dependency problems
|
||||
return row ? new NoteRevision(row) : null;
|
||||
}
|
||||
|
||||
/** @returns {Option|null} */
|
||||
getOption(name) {
|
||||
return this.options[name];
|
||||
}
|
||||
|
||||
/** @returns {EtapiToken[]} */
|
||||
getEtapiTokens() {
|
||||
return Object.values(this.etapiTokens);
|
||||
}
|
||||
|
||||
/** @returns {EtapiToken|null} */
|
||||
getEtapiToken(etapiTokenId) {
|
||||
return this.etapiTokens[etapiTokenId];
|
||||
}
|
||||
|
||||
getEntity(entityName, entityId) {
|
||||
if (!entityName || !entityId) {
|
||||
return null;
|
||||
@@ -130,17 +150,19 @@ class Becca {
|
||||
return this[camelCaseEntityName][entityId];
|
||||
}
|
||||
|
||||
/** @returns {RecentNote[]} */
|
||||
getRecentNotesFromQuery(query, params = []) {
|
||||
const rows = sql.getRows(query, params);
|
||||
|
||||
const RecentNote = require("./entities/recent_note.js"); // avoiding circular dependency problems
|
||||
const RecentNote = require("./entities/recent_note"); // avoiding circular dependency problems
|
||||
return rows.map(row => new RecentNote(row));
|
||||
}
|
||||
|
||||
/** @returns {NoteRevision[]} */
|
||||
getNoteRevisionsFromQuery(query, params = []) {
|
||||
const rows = sql.getRows(query, params);
|
||||
|
||||
const NoteRevision = require("./entities/note_revision.js"); // avoiding circular dependency problems
|
||||
const NoteRevision = require("./entities/note_revision"); // avoiding circular dependency problems
|
||||
return rows.map(row => new NoteRevision(row));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user