This commit is contained in:
zadam
2022-04-16 00:17:32 +02:00
parent 987f8e9961
commit 534c71491b
41 changed files with 2223 additions and 200 deletions

View File

@@ -10,6 +10,9 @@ const log = require("../../services/log");
let becca = null;
/**
* Base class for all backend entities.
*/
class AbstractEntity {
beforeSaving() {
this.generateIdIfNecessary();
@@ -62,6 +65,11 @@ class AbstractEntity {
return this.getPojo();
}
/**
* Saves entity - executes SQL, but doesn't commit the transaction on its own
*
* @returns {AbstractEntity}
*/
save() {
const entityName = this.constructor.entityName;
const primaryKeyName = this.constructor.primaryKeyName;
@@ -100,6 +108,11 @@ class AbstractEntity {
return this;
}
/**
* Mark the entity as (soft) deleted. It will be completely erased later.
*
* @param [deleteId=null]
*/
markAsDeleted(deleteId = null) {
const entityId = this[this.constructor.primaryKeyName];
const entityName = this.constructor.entityName;

View File

@@ -9,6 +9,8 @@ const promotedAttributeDefinitionParser = require("../../services/promoted_attri
/**
* Attribute is an abstract concept which has two real uses - label (key - value pair)
* and relation (representing named relationship between source and target note)
*
* @extends AbstractEntity
*/
class Attribute extends AbstractEntity {
static get entityName() { return "attributes"; }

View File

@@ -8,6 +8,8 @@ const dateUtils = require("../../services/date_utils");
/**
* Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple
* parents.
*
* @extends AbstractEntity
*/
class Branch extends AbstractEntity {
static get entityName() { return "branches"; }

View File

@@ -11,6 +11,8 @@ const AbstractEntity = require("./abstract_entity");
*
* The format user is presented with is "<etapiTokenId>_<tokenHash>". This is also called "authToken" to distinguish it
* from tokenHash and token.
*
* @extends AbstractEntity
*/
class EtapiToken extends AbstractEntity {
static get entityName() { return "etapi_tokens"; }

View File

@@ -14,6 +14,8 @@ const RELATION = 'relation';
/**
* Trilium's main entity which can represent text note, image, code note, file attachment etc.
*
* @extends AbstractEntity
*/
class Note extends AbstractEntity {
static get entityName() { return "notes"; }

View File

@@ -11,6 +11,8 @@ const AbstractEntity = require("./abstract_entity");
/**
* NoteRevision represents snapshot of note's title and content at some point in the past.
* It's used for seamless note versioning.
*
* @extends AbstractEntity
*/
class NoteRevision extends AbstractEntity {
static get entityName() { return "note_revisions"; }

View File

@@ -5,6 +5,8 @@ const AbstractEntity = require("./abstract_entity");
/**
* Option represents name-value pair, either directly configurable by the user or some system property.
*
* @extends AbstractEntity
*/
class Option extends AbstractEntity {
static get entityName() { return "options"; }

View File

@@ -5,6 +5,8 @@ const AbstractEntity = require("./abstract_entity");
/**
* RecentNote represents recently visited note.
*
* @extends AbstractEntity
*/
class RecentNote extends AbstractEntity {
static get entityName() { return "recent_notes"; }