server-ts: Fix most errors in bnote

This commit is contained in:
Elian Doran 2024-02-17 10:56:27 +02:00
parent f9ba8ca87d
commit 9aec3390dd
No known key found for this signature in database
10 changed files with 359 additions and 362 deletions

View File

@ -31,9 +31,9 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
protected utcDateCreated?: string; protected utcDateCreated?: string;
protected utcDateModified?: string; protected utcDateModified?: string;
protected dateCreated?: string;
protected dateModified?: string; protected dateModified?: string;
protected isProtected?: boolean; protected isProtected?: boolean;
protected isDeleted?: boolean;
protected isSynced?: boolean; protected isSynced?: boolean;
protected blobId?: string; protected blobId?: string;
@ -92,6 +92,8 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
abstract getPojo(): {}; abstract getPojo(): {};
abstract get isDeleted(): boolean;
/** /**
* Saves entity - executes SQL, but doesn't commit the transaction on its own * Saves entity - executes SQL, but doesn't commit the transaction on its own
*/ */

View File

@ -7,25 +7,28 @@ import sql = require('../../services/sql');
import protectedSessionService = require('../../services/protected_session'); import protectedSessionService = require('../../services/protected_session');
import log = require('../../services/log'); import log = require('../../services/log');
import { AttachmentRow } from './rows'; import { AttachmentRow } from './rows';
import BNote = require('./bnote');
import BBranch = require('./bbranch');
const attachmentRoleToNoteTypeMapping = { const attachmentRoleToNoteTypeMapping = {
'image': 'image' 'image': 'image'
}; };
interface ContentOpts { interface ContentOpts {
// FIXME: Found in bnote.ts, to check if it's actually used and not a typo.
forceSave?: boolean;
/** will also save this BAttachment entity */ /** will also save this BAttachment entity */
forceFullSave: boolean; forceFullSave?: boolean;
/** override frontend heuristics on when to reload, instruct to reload */ /** override frontend heuristics on when to reload, instruct to reload */
forceFrontendReload: boolean; forceFrontendReload?: boolean;
} }
/** /**
* Attachment represent data related/attached to the note. Conceptually similar to attributes, but intended for * Attachment represent data related/attached to the note. Conceptually similar to attributes, but intended for
* larger amounts of data and generally not accessible to the user. * larger amounts of data and generally not accessible to the user.
*
* @extends AbstractBeccaEntity
*/ */
class BAttachment extends AbstractBeccaEntity { class BAttachment extends AbstractBeccaEntity<BAttachment> {
static get entityName() { return "attachments"; } static get entityName() { return "attachments"; }
static get primaryKeyName() { return "attachmentId"; } static get primaryKeyName() { return "attachmentId"; }
static get hashedProperties() { return ["attachmentId", "ownerId", "role", "mime", "title", "blobId", "utcDateScheduledForErasureSince"]; } static get hashedProperties() { return ["attachmentId", "ownerId", "role", "mime", "title", "blobId", "utcDateScheduledForErasureSince"]; }
@ -39,7 +42,7 @@ class BAttachment extends AbstractBeccaEntity {
title: string; title: string;
type?: keyof typeof attachmentRoleToNoteTypeMapping; type?: keyof typeof attachmentRoleToNoteTypeMapping;
position?: number; position?: number;
blobId: string; blobId?: string;
isProtected?: boolean; isProtected?: boolean;
dateModified?: string; dateModified?: string;
utcDateScheduledForErasureSince?: string; utcDateScheduledForErasureSince?: string;

View File

@ -10,10 +10,8 @@ import { AttributeRow, AttributeType } from './rows.js';
/** /**
* Attribute is an abstract concept which has two real uses - label (key - value pair) * Attribute is an abstract concept which has two real uses - label (key - value pair)
* and relation (representing named relationship between source and target note) * and relation (representing named relationship between source and target note)
*
* @extends AbstractBeccaEntity
*/ */
class BAttribute extends AbstractBeccaEntity { class BAttribute extends AbstractBeccaEntity<BAttribute> {
static get entityName() { return "attributes"; } static get entityName() { return "attributes"; }
static get primaryKeyName() { return "attributeId"; } static get primaryKeyName() { return "attributeId"; }
static get hashedProperties() { return ["attributeId", "noteId", "type", "name", "value", "isInheritable"]; } static get hashedProperties() { return ["attributeId", "noteId", "type", "name", "value", "isInheritable"]; }

View File

@ -15,10 +15,8 @@ import { BranchRow } from './rows.js';
* *
* Note that you should not rely on the branch's identity, since it can change easily with a note's move. * Note that you should not rely on the branch's identity, since it can change easily with a note's move.
* Always check noteId instead. * Always check noteId instead.
*
* @extends AbstractBeccaEntity
*/ */
class BBranch extends AbstractBeccaEntity { class BBranch extends AbstractBeccaEntity<BBranch> {
static get entityName() { return "branches"; } static get entityName() { return "branches"; }
static get primaryKeyName() { return "branchId"; } static get primaryKeyName() { return "branchId"; }
// notePosition is not part of hash because it would produce a lot of updates in case of reordering // notePosition is not part of hash because it would produce a lot of updates in case of reordering
@ -27,7 +25,7 @@ class BBranch extends AbstractBeccaEntity {
branchId?: string; branchId?: string;
noteId!: string; noteId!: string;
parentNoteId!: string; parentNoteId!: string;
prefix!: string; prefix!: string | null;
notePosition!: number; notePosition!: number;
isExpanded!: boolean; isExpanded!: boolean;
utcDateModified?: string; utcDateModified?: string;

View File

@ -2,8 +2,8 @@
import { EtapiTokenRow } from "./rows"; import { EtapiTokenRow } from "./rows";
const dateUtils = require('../../services/date_utils'); import dateUtils = require('../../services/date_utils');
const AbstractBeccaEntity = require('./abstract_becca_entity.js'); import AbstractBeccaEntity = require('./abstract_becca_entity');
/** /**
* EtapiToken is an entity representing token used to authenticate against Trilium REST API from client applications. * EtapiToken is an entity representing token used to authenticate against Trilium REST API from client applications.
@ -13,10 +13,8 @@ const AbstractBeccaEntity = require('./abstract_becca_entity.js');
* *
* The format user is presented with is "<etapiTokenId>_<tokenHash>". This is also called "authToken" to distinguish it * The format user is presented with is "<etapiTokenId>_<tokenHash>". This is also called "authToken" to distinguish it
* from tokenHash and token. * from tokenHash and token.
*
* @extends AbstractBeccaEntity
*/ */
class BEtapiToken extends AbstractBeccaEntity { class BEtapiToken extends AbstractBeccaEntity<BEtapiToken> {
static get entityName() { return "etapi_tokens"; } static get entityName() { return "etapi_tokens"; }
static get primaryKeyName() { return "etapiTokenId"; } static get primaryKeyName() { return "etapiTokenId"; }
static get hashedProperties() { return ["etapiTokenId", "name", "tokenHash", "utcDateCreated", "utcDateModified", "isDeleted"]; } static get hashedProperties() { return ["etapiTokenId", "name", "tokenHash", "utcDateCreated", "utcDateModified", "isDeleted"]; }

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ import { AttachmentRow, RevisionRow } from './rows';
interface ContentOpts { interface ContentOpts {
/** will also save this BRevision entity */ /** will also save this BRevision entity */
forceSave: boolean; forceSave?: boolean;
} }
interface GetByIdOpts { interface GetByIdOpts {
@ -22,7 +22,7 @@ interface GetByIdOpts {
* Revision represents a snapshot of note's title and content at some point in the past. * Revision represents a snapshot of note's title and content at some point in the past.
* It's used for seamless note versioning. * It's used for seamless note versioning.
*/ */
class BRevision extends AbstractBeccaEntity { class BRevision extends AbstractBeccaEntity<BRevision> {
static get entityName() { return "revisions"; } static get entityName() { return "revisions"; }
static get primaryKeyName() { return "revisionId"; } static get primaryKeyName() { return "revisionId"; }
static get hashedProperties() { return ["revisionId", "noteId", "title", "isProtected", "dateLastEdited", "dateCreated", static get hashedProperties() { return ["revisionId", "noteId", "title", "isProtected", "dateLastEdited", "dateCreated",
@ -113,7 +113,7 @@ class BRevision extends AbstractBeccaEntity {
} }
} }
setContent(content: any, opts: ContentOpts) { setContent(content: any, opts: ContentOpts = {}) {
this._setContent(content, opts); this._setContent(content, opts);
} }
@ -200,4 +200,4 @@ class BRevision extends AbstractBeccaEntity {
} }
} }
module.exports = BRevision; export = BRevision;

View File

@ -2,30 +2,31 @@
export interface AttachmentRow { export interface AttachmentRow {
attachmentId?: string; attachmentId?: string;
ownerId: string; ownerId?: string;
role: string; role: string;
mime: string; mime: string;
title?: string; title?: string;
position?: number; position?: number;
blobId: string; blobId?: string;
isProtected?: boolean; isProtected?: boolean;
dateModified?: string; dateModified?: string;
utcDateModified?: string; utcDateModified?: string;
utcDateScheduledForErasureSince?: string; utcDateScheduledForErasureSince?: string;
contentLength?: number; contentLength?: number;
content?: string;
} }
export interface RevisionRow { export interface RevisionRow {
revisionId: string; revisionId?: string;
noteId: string; noteId: string;
type: string; type: string;
mime: string; mime: string;
isProtected: boolean; isProtected?: boolean;
title: string; title: string;
blobId: string; blobId?: string;
dateLastEdited: string; dateLastEdited?: string;
dateCreated: string; dateCreated: string;
utcDateLastEdited: string; utcDateLastEdited?: string;
utcDateCreated: string; utcDateCreated: string;
utcDateModified: string; utcDateModified: string;
contentLength?: number; contentLength?: number;
@ -71,7 +72,7 @@ export interface AttributeRow {
position: number; position: number;
value: string; value: string;
isInheritable: boolean; isInheritable: boolean;
utcDateModified: string; utcDateModified?: string;
} }
export interface BranchRow { export interface BranchRow {
@ -82,4 +83,24 @@ export interface BranchRow {
notePosition: number; notePosition: number;
isExpanded: boolean; isExpanded: boolean;
utcDateModified?: string; utcDateModified?: string;
}
/**
* There are many different Note types, some of which are entirely opaque to the
* end user. Those types should be used only for checking against, they are
* not for direct use.
*/
export type NoteType = ("file" | "image" | "search" | "noteMap" | "launcher" | "doc" | "contentWidget" | "text" | "relationMap" | "render" | "canvas" | "mermaid" | "book" | "webView" | "code");
export interface NoteRow {
noteId: string;
title: string;
type: NoteType;
mime: string;
isProtected: boolean;
blobId: string;
dateCreated: string;
dateModified: string;
utcDateCreated: string;
utcDateModified: string;
} }

View File

@ -10,10 +10,10 @@ class TaskContext {
private taskId: string; private taskId: string;
private taskType: string | null; private taskType: string | null;
private data: {} | null; private data: {} | null;
private noteDeletionHandlerTriggered: boolean;
private progressCount: number; private progressCount: number;
private lastSentCountTs: number; private lastSentCountTs: number;
noteDeletionHandlerTriggered: boolean;
constructor(taskId: string, taskType: string | null = null, data: {} | null = {}) { constructor(taskId: string, taskType: string | null = null, data: {} | null = {}) {
this.taskId = taskId; this.taskId = taskId;
this.taskType = taskType; this.taskType = taskType;

View File

@ -12,7 +12,7 @@ function newEntityId() {
return randomString(12); return randomString(12);
} }
function randomString(length: number) { function randomString(length: number): string {
return randtoken.generate(length); return randtoken.generate(length);
} }