Skip to content

Build your personal knowledge base with Trilium Notes

chore(core): partially integrate becca

Elian Doran320d8e3b4597
diff --git a/apps/server/src/becca/becca-interface.ts b/packages/trilium-core/src/becca/becca-interface.ts
similarity index 92%
rename from apps/server/src/becca/becca-interface.ts
rename to packages/trilium-core/src/becca/becca-interface.ts
index 1a8203f436..a70a07e1e7 100644
--- a/apps/server/src/becca/becca-interface.ts
+++ b/packages/trilium-core/src/becca/becca-interface.ts
@@ -1,4 +1,3 @@
-import sql from "../services/sql.js";
import NoteSet from "../services/search/note_set.js";
import NotFoundError from "../errors/not_found_error.js";
import type BOption from "./entities/boption.js";
@@ -12,6 +11,7 @@ import type { AttachmentRow, BlobRow, RevisionRow } from "@triliumnext/commons";
import BBlob from "./entities/bblob.js";
import BRecentNote from "./entities/brecent_note.js";
import type AbstractBeccaEntity from "./entities/abstract_becca_entity.js";
+import { getSql } from "src/services/sql/index.js";
/**
* Becca is a backend cache of all notes, branches, and attributes.
@@ -151,7 +151,7 @@ export default class Becca {
}
getRevision(revisionId: string): BRevision | null {
- const row = sql.getRow<RevisionRow | null>("SELECT * FROM revisions WHERE revisionId = ?", [revisionId]);
+ const row = getSql().getRow<RevisionRow | null>("SELECT * FROM revisions WHERE revisionId = ?", [revisionId]);
return row ? new BRevision(row) : null;
}
@@ -170,7 +170,7 @@ export default class Becca {
JOIN blobs USING (blobId)
WHERE attachmentId = ? AND isDeleted = 0`;
- return sql.getRows<AttachmentRow>(query, [attachmentId]).map((row) => new BAttachment(row))[0];
+ return getSql().getRows<AttachmentRow>(query, [attachmentId]).map((row) => new BAttachment(row))[0];
}
getAttachmentOrThrow(attachmentId: string): BAttachment {
@@ -182,7 +182,7 @@ export default class Becca {
}
getAttachments(attachmentIds: string[]): BAttachment[] {
- return sql.getManyRows<AttachmentRow>("SELECT * FROM attachments WHERE attachmentId IN (???) AND isDeleted = 0", attachmentIds).map((row) => new BAttachment(row));
+ return getSql().getManyRows<AttachmentRow>("SELECT * FROM attachments WHERE attachmentId IN (???) AND isDeleted = 0", attachmentIds).map((row) => new BAttachment(row));
}
getBlob(entity: { blobId?: string }): BBlob | null {
@@ -190,7 +190,7 @@ export default class Becca {
return null;
}
- const row = sql.getRow<BlobRow | null>("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]);
+ const row = getSql().getRow<BlobRow | null>("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]);
return row ? new BBlob(row) : null;
}
@@ -227,12 +227,12 @@ export default class Becca {
}
getRecentNotesFromQuery(query: string, params: string[] = []): BRecentNote[] {
- const rows = sql.getRows<BRecentNote>(query, params);
+ const rows = getSql().getRows<BRecentNote>(query, params);
return rows.map((row) => new BRecentNote(row));
}
getRevisionsFromQuery(query: string, params: string[] = []): BRevision[] {
- const rows = sql.getRows<RevisionRow>(query, params);
+ const rows = getSql().getRows<RevisionRow>(query, params);
return rows.map((row) => new BRevision(row));
}
diff --git a/apps/server/src/becca/becca.ts b/packages/trilium-core/src/becca/becca.ts
similarity index 100%
rename from apps/server/src/becca/becca.ts
rename to packages/trilium-core/src/becca/becca.ts
diff --git a/apps/server/src/becca/becca_loader.ts b/packages/trilium-core/src/becca/becca_loader.ts
similarity index 95%
rename from apps/server/src/becca/becca_loader.ts
rename to packages/trilium-core/src/becca/becca_loader.ts
index 3d5e7c3207..e2cd1804c1 100644
--- a/apps/server/src/becca/becca_loader.ts
+++ b/packages/trilium-core/src/becca/becca_loader.ts
@@ -1,10 +1,8 @@
import type { AttributeRow, BranchRow, EtapiTokenRow, NoteRow, OptionRow } from "@triliumnext/commons";
-import { events as eventService } from "@triliumnext/core";
+import eventService from "../services/events";
import entityConstructor from "../becca/entity_constructor.js";
-import cls from "../services/cls.js";
-import log from "../services/log.js";
-import sql from "../services/sql.js";
+import { getLog } from "../services/log.js";
import { dbReady } from "../services/sql_init.js";
import ws from "../services/ws.js";
import becca from "./becca.js";
@@ -14,13 +12,15 @@ import BBranch from "./entities/bbranch.js";
import BEtapiToken from "./entities/betapi_token.js";
import BNote from "./entities/bnote.js";
import BOption from "./entities/boption.js";
+import { getSql } from "src/services/sql/index.js";
+import { getContext } from "src/services/context.js";
export const beccaLoaded = new Promise<void>(async (res, rej) => {
// We have to import async since options init requires keyboard actions which require translations.
const options_init = (await import("../services/options_init.js")).default;
dbReady.then(() => {
- cls.init(() => {
+ getContext().init(() => {
load();
options_init.initStartupOptions();
@@ -35,6 +35,7 @@ function load() {
becca.reset();
// we know this is slow and the total becca load time is logged
+ const sql = getSql();
sql.disableSlowQueryLogging(() => {
// using a raw query and passing arrays to avoid allocating new objects,
// this is worth it for the becca load since it happens every run and blocks the app until finished
@@ -71,7 +72,7 @@ function load() {
becca.loaded = true;
- log.info(`Becca (note cache) load took ${Date.now() - start}ms`);
+ getLog().info(`Becca (note cache) load took ${Date.now() - start}ms`);
}
function reload(reason: string) {
@@ -283,7 +284,7 @@ eventService.subscribeBeccaLoader(eventService.ENTER_PROTECTED_SESSION, () => {
try {
becca.decryptProtectedNotes();
} catch (e: any) {
- log.error(`Could not decrypt protected notes: ${e.message} ${e.stack}`);
+ getLog().error(`Could not decrypt protected notes: ${e.message} ${e.stack}`);
}
});
diff --git a/apps/server/src/becca/becca_service.ts b/packages/trilium-core/src/becca/becca_service.ts
similarity index 91%
rename from apps/server/src/becca/becca_service.ts
rename to packages/trilium-core/src/becca/becca_service.ts
index 92967da342..a5a4001a91 100644
--- a/apps/server/src/becca/becca_service.ts
+++ b/packages/trilium-core/src/becca/becca_service.ts
@@ -1,8 +1,8 @@
"use strict";
import becca from "./becca.js";
-import cls from "../services/cls.js";
-import log from "../services/log.js";
+import { getLog } from "../services/log.js";
+import { getContext } from "src/services/context.js";
function isNotePathArchived(notePath: string[]) {
const noteId = notePath[notePath.length - 1];
@@ -29,7 +29,7 @@ function getNoteTitle(childNoteId: string, parentNoteId?: string) {
const parentNote = parentNoteId ? becca.notes[parentNoteId] : null;
if (!childNote) {
- log.info(`Cannot find note '${childNoteId}'`);
+ getLog().info(`Cannot find note '${childNoteId}'`);
return "[error fetching title]";
}
@@ -50,7 +50,7 @@ function getNoteTitleAndIcon(childNoteId: string, parentNoteId?: string) {
const parentNote = parentNoteId ? becca.notes[parentNoteId] : null;
if (!childNote) {
- log.info(`Cannot find note '${childNoteId}'`);
+ getLog().info(`Cannot find note '${childNoteId}'`);
return {
title: "[error fetching title]"
}
@@ -82,7 +82,7 @@ function getNoteTitleArrayForPath(notePathArray: string[]) {
let hoistedNotePassed = false;
// this is a notePath from outside of hoisted subtree, so the full title path needs to be returned
- const hoistedNoteId = cls.getHoistedNoteId();
+ const hoistedNoteId = getContext().getHoistedNoteId();
const outsideOfHoistedSubtree = !notePathArray.includes(hoistedNoteId);
for (const noteId of notePathArray) {
diff --git a/apps/server/src/becca/entities/abstract_becca_entity.ts b/packages/trilium-core/src/becca/entities/abstract_becca_entity.ts
similarity index 95%
rename from apps/server/src/becca/entities/abstract_becca_entity.ts
rename to packages/trilium-core/src/becca/entities/abstract_becca_entity.ts
index 0792c6bd48..b224349ca2 100644
--- a/apps/server/src/becca/entities/abstract_becca_entity.ts
+++ b/packages/trilium-core/src/becca/entities/abstract_becca_entity.ts
@@ -1,15 +1,15 @@
-import { events as eventService } from "@triliumnext/core";
+import eventService from "../../services/events";
import blobService from "../../services/blob.js";
-import cls from "../../services/cls.js";
-import dateUtils from "../../services/date_utils.js";
+import * as cls from "../../services/context";
+import dateUtils from "../../services/utils/date";
import entityChangesService from "../../services/entity_changes.js";
-import log from "../../services/log.js";
+import { getLog } from "../../services/log.js";
import protectedSessionService from "../../services/protected_session.js";
-import sql from "../../services/sql.js";
import utils from "../../services/utils.js";
import becca from "../becca.js";
import type { ConstructorData,default as Becca } from "../becca-interface.js";
+import { getSql } from "src/services/sql";
interface ContentOpts {
forceSave?: boolean;
@@ -110,6 +110,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
const pojo = this.getPojoToSave();
+ const sql = getSql();
sql.transactional(() => {
sql.upsert(entityName, primaryKeyName, pojo);
@@ -166,7 +167,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
}
}
- sql.transactional(() => {
+ getSql().transactional(() => {
const newBlobId = this.saveBlob(content, unencryptedContentForHashCalculation, opts);
const oldBlobId = this.blobId;
@@ -182,6 +183,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
}
private deleteBlobIfNotUsed(oldBlobId: string) {
+ const sql = getSql();
if (sql.getValue("SELECT 1 FROM notes WHERE blobId = ? LIMIT 1", [oldBlobId])) {
return;
}
@@ -218,6 +220,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
* notes/attachments), but the trade-off comes out clearly positive.
*/
const newBlobId = utils.hashedBlobId(unencryptedContentForHashCalculation);
+ const sql = getSql();
const blobNeedsInsert = !sql.getValue("SELECT 1 FROM blobs WHERE blobId = ?", [newBlobId]);
if (!blobNeedsInsert) {
@@ -258,6 +261,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
}
protected _getContent(): string | Buffer {
+ const sql = getSql();
const row = sql.getRow<{ content: string | Buffer }>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]);
if (!row) {
@@ -280,6 +284,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
this.utcDateModified = dateUtils.utcNowDateTime();
+ const sql = getSql();
sql.execute(
/*sql*/`UPDATE ${entityName} SET isDeleted = 1, deleteId = ?, utcDateModified = ?
WHERE ${constructorData.primaryKeyName} = ?`,
@@ -292,7 +297,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
sql.execute(/*sql*/`UPDATE ${entityName} SET dateModified = ? WHERE ${constructorData.primaryKeyName} = ?`, [this.dateModified, entityId]);
}
- log.info(`Marking ${entityName} ${entityId} as deleted`);
+ getLog().info(`Marking ${entityName} ${entityId} as deleted`);
this.putEntityChange(true);
@@ -306,13 +311,14 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
this.utcDateModified = dateUtils.utcNowDateTime();
+ const sql = getSql();
sql.execute(
/*sql*/`UPDATE ${entityName} SET isDeleted = 1, utcDateModified = ?
WHERE ${constructorData.primaryKeyName} = ?`,
[this.utcDateModified, entityId]
);
- log.info(`Marking ${entityName} ${entityId} as deleted`);
+ getLog().info(`Marking ${entityName} ${entityId} as deleted`);
this.putEntityChange(true);
diff --git a/apps/server/src/becca/entities/battachment.ts b/packages/trilium-core/src/becca/entities/battachment.ts
similarity index 96%
rename from apps/server/src/becca/entities/battachment.ts
rename to packages/trilium-core/src/becca/entities/battachment.ts
index 924dd972ab..cfd0a638b9 100644
--- a/apps/server/src/becca/entities/battachment.ts
+++ b/packages/trilium-core/src/becca/entities/battachment.ts
@@ -2,15 +2,15 @@
import type { AttachmentRow } from "@triliumnext/commons";
-import dateUtils from "../../services/date_utils.js";
-import log from "../../services/log.js";
+import dateUtils from "../../services/utils/date";
+import { getLog } from "../../services/log.js";
import noteService from "../../services/notes.js";
import protectedSessionService from "../../services/protected_session.js";
-import sql from "../../services/sql.js";
import utils from "../../services/utils.js";
import AbstractBeccaEntity from "./abstract_becca_entity.js";
import type BBranch from "./bbranch.js";
import type BNote from "./bnote.js";
+import { getSql } from "src/services/sql/index.js";
const attachmentRoleToNoteTypeMapping = {
image: "image",
@@ -131,7 +131,7 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
this.title = protectedSessionService.decryptString(this.title) || "";
this.isDecrypted = true;
} catch (e: any) {
- log.error(`Could not decrypt attachment ${this.attachmentId}: ${e.message} ${e.stack}`);
+ getLog().error(`Could not decrypt attachment ${this.attachmentId}: ${e.message} ${e.stack}`);
}
}
}
@@ -210,7 +210,7 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
if (this.position === undefined || this.position === null) {
this.position =
10 +
- sql.getValue<number>(
+ getSql().getValue<number>(
/*sql*/`SELECT COALESCE(MAX(position), 0)
FROM attachments
WHERE ownerId = ?`,
diff --git a/apps/server/src/becca/entities/battribute.ts b/packages/trilium-core/src/becca/entities/battribute.ts
similarity index 99%
rename from apps/server/src/becca/entities/battribute.ts
rename to packages/trilium-core/src/becca/entities/battribute.ts
index 6ff1246fcf..5e4028fe65 100644
--- a/apps/server/src/becca/entities/battribute.ts
+++ b/packages/trilium-core/src/becca/entities/battribute.ts
@@ -2,7 +2,7 @@
import BNote from "./bnote.js";
import AbstractBeccaEntity from "./abstract_becca_entity.js";
-import dateUtils from "../../services/date_utils.js";
+import dateUtils from "../../services/utils/date";
import promotedAttributeDefinitionParser from "../../services/promoted_attribute_definition_parser.js";
import sanitizeAttributeName from "../../services/sanitize_attribute_name.js";
import type { AttributeRow, AttributeType } from "@triliumnext/commons";
diff --git a/apps/server/src/becca/entities/bblob.ts b/packages/trilium-core/src/becca/entities/bblob.ts
similarity index 100%
rename from apps/server/src/becca/entities/bblob.ts
rename to packages/trilium-core/src/becca/entities/bblob.ts
diff --git a/apps/server/src/becca/entities/bbranch.ts b/packages/trilium-core/src/becca/entities/bbranch.ts
similarity index 96%
rename from apps/server/src/becca/entities/bbranch.ts
rename to packages/trilium-core/src/becca/entities/bbranch.ts
index d1eb91a9ef..4c7be548b9 100644
--- a/apps/server/src/becca/entities/bbranch.ts
+++ b/packages/trilium-core/src/becca/entities/bbranch.ts
@@ -2,14 +2,14 @@
import type { BranchRow } from "@triliumnext/commons";
-import cls from "../../services/cls.js";
-import dateUtils from "../../services/date_utils.js";
+import dateUtils from "../../services/utils/date";
import handlers from "../../services/handlers.js";
-import log from "../../services/log.js";
+import { getLog } from "../../services/log.js";
import TaskContext from "../../services/task_context.js";
import utils from "../../services/utils.js";
import AbstractBeccaEntity from "./abstract_becca_entity.js";
import BNote from "./bnote.js";
+import { getContext } from "src/services/context";
/**
* Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple
@@ -160,7 +160,7 @@ class BBranch extends AbstractBeccaEntity<BBranch> {
}
}
- if ((this.noteId === "root" || this.noteId === cls.getHoistedNoteId()) && !this.isWeak) {
+ if ((this.noteId === "root" || this.noteId === getContext().getHoistedNoteId()) && !this.isWeak) {
throw new Error("Can't delete root or hoisted branch/note");
}
@@ -181,7 +181,7 @@ class BBranch extends AbstractBeccaEntity<BBranch> {
// first delete children and then parent - this will show up better in recent changes
- log.info(`Deleting note '${note.noteId}'`);
+ getLog().info(`Deleting note '${note.noteId}'`);
this.becca.notes[note.noteId].isBeingDeleted = true;
@@ -200,9 +200,9 @@ class BBranch extends AbstractBeccaEntity<BBranch> {
note.markAsDeleted(deleteId);
return true;
- }
+ }
return false;
-
+
}
override beforeSaving() {
@@ -269,7 +269,7 @@ class BBranch extends AbstractBeccaEntity<BBranch> {
existingBranch.notePosition = notePosition;
}
return existingBranch;
- }
+ }
return new BBranch({
noteId: this.noteId,
parentNoteId,
@@ -277,7 +277,7 @@ class BBranch extends AbstractBeccaEntity<BBranch> {
prefix: this.prefix,
isExpanded: this.isExpanded
});
-
+
}
getParentNote() {
diff --git a/apps/server/src/becca/entities/betapi_token.ts b/packages/trilium-core/src/becca/entities/betapi_token.ts
similarity index 97%
rename from apps/server/src/becca/entities/betapi_token.ts
rename to packages/trilium-core/src/becca/entities/betapi_token.ts
index c355d2c8f0..d76ede6bdc 100644
--- a/apps/server/src/becca/entities/betapi_token.ts
+++ b/packages/trilium-core/src/becca/entities/betapi_token.ts
@@ -2,7 +2,7 @@
import type { EtapiTokenRow } from "@triliumnext/commons";
-import dateUtils from "../../services/date_utils.js";
+import dateUtils from "../../services/utils/date";
import AbstractBeccaEntity from "./abstract_becca_entity.js";
/**
diff --git a/apps/server/src/becca/entities/bnote.ts b/packages/trilium-core/src/becca/entities/bnote.ts
similarity index 98%
rename from apps/server/src/becca/entities/bnote.ts
rename to packages/trilium-core/src/becca/entities/bnote.ts
index 2ed302ccc6..ea3c60803c 100644
--- a/apps/server/src/becca/entities/bnote.ts
+++ b/packages/trilium-core/src/becca/entities/bnote.ts
@@ -3,15 +3,14 @@ import { dayjs } from "@triliumnext/commons";
import { events as eventService } from "@triliumnext/core";
import cloningService from "../../services/cloning.js";
-import dateUtils from "../../services/date_utils.js";
+import dateUtils from "../../services/utils/date";
import eraseService from "../../services/erase.js";
import handlers from "../../services/handlers.js";
-import log from "../../services/log.js";
+import log, { getLog } from "../../services/log.js";
import noteService from "../../services/notes.js";
import optionService from "../../services/options.js";
import protectedSessionService from "../../services/protected_session.js";
import searchService from "../../services/search/services/search.js";
-import sql from "../../services/sql.js";
import TaskContext from "../../services/task_context.js";
import utils from "../../services/utils.js";
import type { NotePojo } from "../becca-interface.js";
@@ -20,6 +19,7 @@ import BAttachment from "./battachment.js";
import BAttribute from "./battribute.js";
import type BBranch from "./bbranch.js";
import BRevision from "./brevision.js";
+import { getSql } from "src/services/sql/index.js";
const LABEL = "label";
const RELATION = "relation";
@@ -891,7 +891,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
const becca = this.becca;
return result.searchResultNoteIds.map((resultNoteId) => becca.notes[resultNoteId]).filter((note) => !!note);
} catch (e: any) {
- log.error(`Could not resolve search note ${this.noteId}: ${e.message}`);
+ getLog().error(`Could not resolve search note ${this.noteId}: ${e.message}`);
return [];
}
}
@@ -909,7 +909,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
addSubtreeNotesInner(resultNote, searchNote);
}
} catch (e: any) {
- log.error(`Could not resolve search note ${searchNote?.noteId}: ${e.message}`);
+ getLog().error(`Could not resolve search note ${searchNote?.noteId}: ${e.message}`);
}
}
@@ -1093,7 +1093,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
}
getRevisions(): BRevision[] {
- return sql.getRows<RevisionRow>("SELECT * FROM revisions WHERE noteId = ? ORDER BY revisions.utcDateCreated ASC", [this.noteId]).map((row) => new BRevision(row));
+ return getSql().getRows<RevisionRow>("SELECT * FROM revisions WHERE noteId = ? ORDER BY revisions.utcDateCreated ASC", [this.noteId]).map((row) => new BRevision(row));
}
getAttachments() {
@@ -1104,7 +1104,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
WHERE ownerId = ? AND isDeleted = 0
ORDER BY position`;
- return sql.getRows<AttachmentRow>(query, [this.noteId]).map((row) => new BAttachment(row));
+ return getSql().getRows<AttachmentRow>(query, [this.noteId]).map((row) => new BAttachment(row));
}
getAttachmentById(attachmentId: string) {
@@ -1114,11 +1114,11 @@ class BNote extends AbstractBeccaEntity<BNote> {
JOIN blobs USING (blobId)
WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`;
- return sql.getRows<AttachmentRow>(query, [this.noteId, attachmentId]).map((row) => new BAttachment(row))[0];
+ return getSql().getRows<AttachmentRow>(query, [this.noteId, attachmentId]).map((row) => new BAttachment(row))[0];
}
getAttachmentsByRole(role: string): BAttachment[] {
- return sql
+ return getSql()
.getRows<AttachmentRow>(
`
SELECT attachments.*
@@ -1527,7 +1527,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
this.isDecrypted = true;
} catch (e: any) {
- log.error(`Could not decrypt note ${this.noteId}: ${e.message} ${e.stack}`);
+ getLog().error(`Could not decrypt note ${this.noteId}: ${e.message} ${e.stack}`);
}
}
}
@@ -1549,7 +1549,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
}
saveRevision(): BRevision {
- return sql.transactional(() => {
+ return getSql().transactional(() => {
let noteContent = this.getContent();
const revision = new BRevision(
diff --git a/apps/server/src/becca/entities/boption.ts b/packages/trilium-core/src/becca/entities/boption.ts
similarity index 95%
rename from apps/server/src/becca/entities/boption.ts
rename to packages/trilium-core/src/becca/entities/boption.ts
index 7c841931b9..f0cd473e9b 100644
--- a/apps/server/src/becca/entities/boption.ts
+++ b/packages/trilium-core/src/becca/entities/boption.ts
@@ -1,6 +1,6 @@
"use strict";
-import dateUtils from "../../services/date_utils.js";
+import dateUtils from "../../services/utils/date";
import AbstractBeccaEntity from "./abstract_becca_entity.js";
import type { OptionRow } from "@triliumnext/commons";
diff --git a/apps/server/src/becca/entities/brecent_note.ts b/packages/trilium-core/src/becca/entities/brecent_note.ts
similarity index 94%
rename from apps/server/src/becca/entities/brecent_note.ts
rename to packages/trilium-core/src/becca/entities/brecent_note.ts
index bfaa465447..d950df369e 100644
--- a/apps/server/src/becca/entities/brecent_note.ts
+++ b/packages/trilium-core/src/becca/entities/brecent_note.ts
@@ -2,7 +2,7 @@
import type { RecentNoteRow } from "@triliumnext/commons";
-import dateUtils from "../../services/date_utils.js";
+import dateUtils from "../../services/utils/date";
import AbstractBeccaEntity from "./abstract_becca_entity.js";
/**
diff --git a/apps/server/src/becca/entities/brevision.spec.ts b/packages/trilium-core/src/becca/entities/brevision.spec.ts
similarity index 100%
rename from apps/server/src/becca/entities/brevision.spec.ts
rename to packages/trilium-core/src/becca/entities/brevision.spec.ts
diff --git a/apps/server/src/becca/entities/brevision.ts b/packages/trilium-core/src/becca/entities/brevision.ts
similarity index 96%
rename from apps/server/src/becca/entities/brevision.ts
rename to packages/trilium-core/src/becca/entities/brevision.ts
index 88f647db29..2df8a4c9e6 100644
--- a/apps/server/src/becca/entities/brevision.ts
+++ b/packages/trilium-core/src/becca/entities/brevision.ts
@@ -2,13 +2,13 @@
import protectedSessionService from "../../services/protected_session.js";
import utils from "../../services/utils.js";
-import dateUtils from "../../services/date_utils.js";
+import dateUtils from "../../services/utils/date";
import becca from "../becca.js";
import AbstractBeccaEntity from "./abstract_becca_entity.js";
-import sql from "../../services/sql.js";
import BAttachment from "./battachment.js";
import type { AttachmentRow, NoteType, RevisionPojo, RevisionRow } from "@triliumnext/commons";
import eraseService from "../../services/erase.js";
+import { getSql } from "src/services/sql/index.js";
interface ContentOpts {
/** will also save this BRevision entity */
@@ -125,7 +125,7 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
}
getAttachments(): BAttachment[] {
- return sql
+ return getSql()
.getRows<AttachmentRow>(
`
SELECT attachments.*
@@ -147,11 +147,11 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`
: /*sql*/`SELECT * FROM attachments WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`;
- return sql.getRows<AttachmentRow>(query, [this.revisionId, attachmentId]).map((row) => new BAttachment(row))[0];
+ return getSql().getRows<AttachmentRow>(query, [this.revisionId, attachmentId]).map((row) => new BAttachment(row))[0];
}
getAttachmentsByRole(role: string): BAttachment[] {
- return sql
+ return getSql()
.getRows<AttachmentRow>(
`
SELECT attachments.*
diff --git a/apps/server/src/becca/entity_constructor.ts b/packages/trilium-core/src/becca/entity_constructor.ts
similarity index 100%
rename from apps/server/src/becca/entity_constructor.ts
rename to packages/trilium-core/src/becca/entity_constructor.ts
diff --git a/apps/server/src/becca/similarity.spec.ts b/packages/trilium-core/src/becca/similarity.spec.ts
similarity index 100%
rename from apps/server/src/becca/similarity.spec.ts
rename to packages/trilium-core/src/becca/similarity.spec.ts
diff --git a/apps/server/src/becca/similarity.ts b/packages/trilium-core/src/becca/similarity.ts
similarity index 98%
rename from apps/server/src/becca/similarity.ts
rename to packages/trilium-core/src/becca/similarity.ts
index 10a0e706dc..2696c9c51b 100644
--- a/apps/server/src/becca/similarity.ts
+++ b/packages/trilium-core/src/becca/similarity.ts
@@ -1,7 +1,7 @@
import becca from "./becca.js";
-import log from "../services/log.js";
+import { getLog } from "../services/log.js";
import beccaService from "./becca_service.js";
-import dateUtils from "../services/date_utils.js";
+import dateUtils from "../services/utils/date";
import { parse } from "node-html-parser";
import type BNote from "./entities/bnote.js";
import { SimilarNote } from "@triliumnext/commons";
@@ -359,7 +359,7 @@ async function findSimilarNotes(noteId: string): Promise<SimilarNote[] | undefin
let factor = 1;
if (!value.startsWith) {
- log.info(`Unexpected falsy value for attribute ${JSON.stringify(attr.getPojo())}`);
+ getLog().info(`Unexpected falsy value for attribute ${JSON.stringify(attr.getPojo())}`);
continue;
} else if (value.startsWith("http")) {
value = filterUrlValue(value);
diff --git a/packages/trilium-core/src/services/events.ts b/packages/trilium-core/src/services/events.ts
index 5ffc93f82e..dcdc5793c4 100644
--- a/packages/trilium-core/src/services/events.ts
+++ b/packages/trilium-core/src/services/events.ts
@@ -1,4 +1,4 @@
-import log from "./log.js";
+import log, { getLog } from "./log.js";
const NOTE_TITLE_CHANGED = "NOTE_TITLE_CHANGED";
const ENTER_PROTECTED_SESSION = "ENTER_PROTECTED_SESSION";
@@ -52,7 +52,7 @@ function emit(eventType: string, data?: any) {
try {
listener(data);
} catch (e: any) {
- log.error(`Listener threw error: ${e.message}, stack: ${e.stack}`);
+ getLog().error(`Listener threw error: ${e.message}, stack: ${e.stack}`);
// we won't stop execution because of listener
}
}