mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-01-07 05:19:53 -06:00
server-ts: Address requested changes
This commit is contained in:
@@ -11,6 +11,7 @@ import BAttachment = require('./entities/battachment');
|
||||
import { AttachmentRow, RevisionRow } from './entities/rows';
|
||||
import BBlob = require('./entities/bblob');
|
||||
import BRecentNote = require('./entities/brecent_note');
|
||||
import AbstractBeccaEntity = require('./entities/abstract_becca_entity');
|
||||
|
||||
interface AttachmentOpts {
|
||||
includeContentLength?: boolean;
|
||||
@@ -95,7 +96,7 @@ class Becca {
|
||||
return this.notes[noteId];
|
||||
}
|
||||
|
||||
getNoteOrThrow(noteId: string): BNote | null {
|
||||
getNoteOrThrow(noteId: string): BNote {
|
||||
const note = this.notes[noteId];
|
||||
if (!note) {
|
||||
throw new NotFoundError(`Note '${noteId}' doesn't exist.`);
|
||||
@@ -190,7 +191,11 @@ class Becca {
|
||||
.map(row => new BAttachment(row));
|
||||
}
|
||||
|
||||
getBlob(entity: { blobId: string }): BBlob | null {
|
||||
getBlob(entity: { blobId?: string }): BBlob | null {
|
||||
if (!entity.blobId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const row = sql.getRow("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]);
|
||||
|
||||
const BBlob = require('./entities/bblob'); // avoiding circular dependency problems
|
||||
@@ -209,8 +214,7 @@ class Becca {
|
||||
return this.etapiTokens[etapiTokenId];
|
||||
}
|
||||
|
||||
/** @returns {AbstractBeccaEntity|null} */
|
||||
getEntity(entityName: string, entityId: string) {
|
||||
getEntity<T extends AbstractBeccaEntity<T>>(entityName: string, entityId: string): AbstractBeccaEntity<T> | null {
|
||||
if (!entityName || !entityId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const beccaLoaded = new Promise((res, rej) => {
|
||||
cls.init(() => {
|
||||
load();
|
||||
|
||||
require('../services/options_init').initStartupOptions();
|
||||
require('../services/options_init.js').initStartupOptions();
|
||||
|
||||
res();
|
||||
});
|
||||
@@ -74,7 +74,7 @@ function reload(reason) {
|
||||
require('../services/ws').reloadFrontend(reason || "becca reloaded");
|
||||
}
|
||||
|
||||
eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entityRow}) => {
|
||||
eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({ entityName, entityRow }) => {
|
||||
if (!becca.loaded) {
|
||||
return;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({entity
|
||||
postProcessEntityUpdate(entityName, entityRow);
|
||||
});
|
||||
|
||||
eventService.subscribeBeccaLoader(eventService.ENTITY_CHANGED, ({entityName, entity}) => {
|
||||
eventService.subscribeBeccaLoader(eventService.ENTITY_CHANGED, ({ entityName, entity }) => {
|
||||
if (!becca.loaded) {
|
||||
return;
|
||||
}
|
||||
@@ -124,7 +124,7 @@ function postProcessEntityUpdate(entityName, entityRow) {
|
||||
}
|
||||
}
|
||||
|
||||
eventService.subscribeBeccaLoader([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({entityName, entityId}) => {
|
||||
eventService.subscribeBeccaLoader([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({ entityName, entityId }) => {
|
||||
if (!becca.loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ interface ContentOpts {
|
||||
forceFrontendReload?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface contains the data that is shared across all the objects of a given derived class of {@link AbstractBeccaEntity}.
|
||||
* For example, all BAttributes will share their content, but all BBranches will have another set of this data.
|
||||
*/
|
||||
interface ConstructorData<T extends AbstractBeccaEntity<T>> {
|
||||
primaryKeyName: string;
|
||||
entityName: string;
|
||||
@@ -26,6 +30,8 @@ interface ConstructorData<T extends AbstractBeccaEntity<T>> {
|
||||
|
||||
/**
|
||||
* Base class for all backend entities.
|
||||
*
|
||||
* @type T the same entity type needed for self-reference in {@link ConstructorData}.
|
||||
*/
|
||||
abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
|
||||
|
||||
@@ -33,10 +39,10 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
|
||||
protected utcDateModified?: string;
|
||||
protected dateCreated?: string;
|
||||
protected dateModified?: string;
|
||||
protected isProtected?: boolean;
|
||||
protected isSynced?: boolean;
|
||||
|
||||
protected blobId?: string;
|
||||
isProtected?: boolean;
|
||||
isSynced?: boolean;
|
||||
blobId?: string;
|
||||
|
||||
protected beforeSaving() {
|
||||
const constructorData = (this.constructor as unknown as ConstructorData<T>);
|
||||
@@ -45,7 +51,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
protected getUtcDateChanged() {
|
||||
getUtcDateChanged() {
|
||||
return this.utcDateModified || this.utcDateCreated;
|
||||
}
|
||||
|
||||
@@ -69,7 +75,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
|
||||
});
|
||||
}
|
||||
|
||||
protected generateHash(isDeleted: boolean): string {
|
||||
generateHash(isDeleted?: boolean): string {
|
||||
const constructorData = (this.constructor as unknown as ConstructorData<T>);
|
||||
let contentToHash = "";
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
|
||||
return this._getContent();
|
||||
}
|
||||
|
||||
setContent(content: any, opts: ContentOpts) {
|
||||
setContent(content: string | Buffer, opts: ContentOpts) {
|
||||
this._setContent(content, opts);
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
|
||||
}
|
||||
}
|
||||
|
||||
setContent(content: any, opts: ContentOpts = {}) {
|
||||
setContent(content: string | Buffer, opts: ContentOpts = {}) {
|
||||
this._setContent(content, opts);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ function getBlobPojo(entityName: string, entityId: string) {
|
||||
if (!entity.hasStringContent()) {
|
||||
pojo.content = null;
|
||||
} else {
|
||||
pojo.content = processContent(pojo.content, entity.isProtected, true);
|
||||
pojo.content = processContent(pojo.content, !!entity.isProtected, true);
|
||||
}
|
||||
|
||||
return pojo;
|
||||
|
||||
Reference in New Issue
Block a user