Skip to content

Build your personal knowledge base with Trilium Notes

server-ts: Solve build errors after merge

Elian Doran08f0c01eefbb
diff --git a/src/becca/becca_loader.ts b/src/becca/becca_loader.ts
index e13641ba90..507828ad59 100644
--- a/src/becca/becca_loader.ts
+++ b/src/becca/becca_loader.ts
@@ -13,6 +13,7 @@ import BEtapiToken = require('./entities/betapi_token');
import cls = require('../services/cls');
import entityConstructor = require('../becca/entity_constructor');
import { AttributeRow, BranchRow, EtapiTokenRow, NoteRow, OptionRow } from './entities/rows';
+import AbstractBeccaEntity = require('./entities/abstract_becca_entity');
const beccaLoaded = new Promise<void>((res, rej) => {
sqlInit.dbReady.then(() => {
@@ -89,7 +90,7 @@ eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({ entity
if (beccaEntity) {
beccaEntity.updateFromRow(entityRow);
} else {
- beccaEntity = new EntityClass();
+ beccaEntity = new EntityClass() as AbstractBeccaEntity<AbstractBeccaEntity<any>>;
beccaEntity.updateFromRow(entityRow);
beccaEntity.init();
}
diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts
index 8b30d2b647..874fecd997 100644
--- a/src/becca/entities/abstract_becca_entity.ts
+++ b/src/becca/entities/abstract_becca_entity.ts
@@ -102,6 +102,10 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
abstract getPojo(): {};
+ abstract init(): void;
+
+ abstract updateFromRow(row: unknown): void;
+
get isDeleted(): boolean {
// TODO: Not sure why some entities don't implement it.
return false;
diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts
index c048c9ed6f..f70cff9e23 100644
--- a/src/becca/entities/battachment.ts
+++ b/src/becca/entities/battachment.ts
@@ -37,10 +37,10 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
noteId?: number;
attachmentId?: string;
/** either noteId or revisionId to which this attachment belongs */
- ownerId: string;
- role: string;
- mime: string;
- title: string;
+ ownerId!: string;
+ role!: string;
+ mime!: string;
+ title!: string;
type?: keyof typeof attachmentRoleToNoteTypeMapping;
position?: number;
blobId?: string;
@@ -54,6 +54,11 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
constructor(row: AttachmentRow) {
super();
+ this.updateFromRow(row);
+ this.decrypt();
+ }
+
+ updateFromRow(row: AttachmentRow): void {
if (!row.ownerId?.trim()) {
throw new Error("'ownerId' must be given to initialize a Attachment entity");
} else if (!row.role?.trim()) {
@@ -76,8 +81,10 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
this.utcDateModified = row.utcDateModified;
this.utcDateScheduledForErasureSince = row.utcDateScheduledForErasureSince;
this.contentLength = row.contentLength;
+ }
- this.decrypt();
+ init(): void {
+ // Do nothing.
}
copy(): BAttachment {
diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts
index 17f7315d1b..cc251ffd01 100644
--- a/src/becca/entities/bnote.ts
+++ b/src/becca/entities/bnote.ts
@@ -1657,6 +1657,10 @@ class BNote extends AbstractBeccaEntity<BNote> {
position
});
+ if (!content) {
+ throw new Error("Attempted to save an attachment with no content.");
+ }
+
attachment.setContent(content, {forceSave: true});
return attachment;
diff --git a/src/becca/entities/boption.ts b/src/becca/entities/boption.ts
index 48abee024c..b06a234311 100644
--- a/src/becca/entities/boption.ts
+++ b/src/becca/entities/boption.ts
@@ -32,6 +32,10 @@ class BOption extends AbstractBeccaEntity<BOption> {
this.utcDateModified = row.utcDateModified;
}
+ init(): void {
+ // Do nothing.
+ }
+
beforeSaving() {
super.beforeSaving();
diff --git a/src/becca/entities/brecent_note.ts b/src/becca/entities/brecent_note.ts
index 0771a5e005..338dae3c5d 100644
--- a/src/becca/entities/brecent_note.ts
+++ b/src/becca/entities/brecent_note.ts
@@ -12,18 +12,26 @@ class BRecentNote extends AbstractBeccaEntity<BRecentNote> {
static get entityName() { return "recent_notes"; }
static get primaryKeyName() { return "noteId"; }
- noteId: string;
- notePath: string;
- utcDateCreated: string;
+ noteId!: string;
+ notePath!: string;
+ utcDateCreated!: string;
constructor(row: RecentNoteRow) {
super();
+ this.updateFromRow(row);
+ }
+
+ updateFromRow(row: RecentNoteRow): void {
this.noteId = row.noteId;
this.notePath = row.notePath;
this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime();
}
+ init(): void {
+ // Do nothing.
+ }
+
getPojo() {
return {
noteId: this.noteId,
diff --git a/src/becca/entities/brevision.ts b/src/becca/entities/brevision.ts
index ba7cc00bad..48d131f0ae 100644
--- a/src/becca/entities/brevision.ts
+++ b/src/becca/entities/brevision.ts
@@ -29,22 +29,30 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
"utcDateLastEdited", "utcDateCreated", "utcDateModified", "blobId"]; }
revisionId?: string;
- noteId: string;
- type: string;
- mime: string;
- isProtected: boolean;
- title: string;
+ noteId!: string;
+ type!: string;
+ mime!: string;
+ isProtected!: boolean;
+ title!: string;
blobId?: string;
dateLastEdited?: string;
- dateCreated: string;
+ dateCreated!: string;
utcDateLastEdited?: string;
- utcDateCreated: string;
+ utcDateCreated!: string;
contentLength?: number;
content?: string;
constructor(row: RevisionRow, titleDecrypted = false) {
super();
+ this.updateFromRow(row);
+ if (this.isProtected && !titleDecrypted) {
+ const decryptedTitle = protectedSessionService.isProtectedSessionAvailable() ? protectedSessionService.decryptString(this.title) : null;
+ this.title = decryptedTitle || "[protected]";
+ }
+ }
+
+ updateFromRow(row: RevisionRow) {
this.revisionId = row.revisionId;
this.noteId = row.noteId;
this.type = row.type;
@@ -58,11 +66,10 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
this.utcDateCreated = row.utcDateCreated;
this.utcDateModified = row.utcDateModified;
this.contentLength = row.contentLength;
+ }
- if (this.isProtected && !titleDecrypted) {
- const decryptedTitle = protectedSessionService.isProtectedSessionAvailable() ? protectedSessionService.decryptString(this.title) : null;
- this.title = decryptedTitle || "[protected]";
- }
+ init() {
+ // Do nothing.
}
getNote() {