Skip to content

Build your personal knowledge base with Trilium Notes

chore(server): fix references to becca loader

Elian Doranf9e22a9ba977
diff --git a/apps/server/src/main.ts b/apps/server/src/main.ts
index 5d9bb8033c..7dd11fa64b 100644
--- a/apps/server/src/main.ts
+++ b/apps/server/src/main.ts
@@ -26,7 +26,7 @@ async function startApplication() {
},
async onTransactionRollback() {
const cls = (await import("./services/cls.js")).default;
- const becca_loader = (await import("./becca/becca_loader.js")).default;
+ const becca_loader = (await import("@triliumnext/core")).becca_loader;
const entity_changes = (await import("./services/entity_changes.js")).default;
const log = (await import("./services/log")).default;
diff --git a/apps/server/src/migrations/0220__migrate_images_to_attachments.ts b/apps/server/src/migrations/0220__migrate_images_to_attachments.ts
index 9e06644c3b..f20e21cb8a 100644
--- a/apps/server/src/migrations/0220__migrate_images_to_attachments.ts
+++ b/apps/server/src/migrations/0220__migrate_images_to_attachments.ts
@@ -1,5 +1,6 @@
+import { becca_loader } from "@triliumnext/core";
+
import becca from "../becca/becca.js";
-import becca_loader from "../becca/becca_loader.js";
import cls from "../services/cls.js";
import log from "../services/log.js";
import sql from "../services/sql.js";
diff --git a/apps/server/src/migrations/0233__migrate_geo_map_to_collection.ts b/apps/server/src/migrations/0233__migrate_geo_map_to_collection.ts
index 7bcf55ebe3..ccd32b1b0d 100644
--- a/apps/server/src/migrations/0233__migrate_geo_map_to_collection.ts
+++ b/apps/server/src/migrations/0233__migrate_geo_map_to_collection.ts
@@ -1,5 +1,6 @@
+import { becca_loader } from "@triliumnext/core";
+
import becca from "../becca/becca";
-import becca_loader from "../becca/becca_loader";
import cls from "../services/cls.js";
import hidden_subtree from "../services/hidden_subtree";
diff --git a/apps/server/src/routes/api/database.ts b/apps/server/src/routes/api/database.ts
index 8ec4b10f46..2fe001a0b5 100644
--- a/apps/server/src/routes/api/database.ts
+++ b/apps/server/src/routes/api/database.ts
@@ -1,8 +1,7 @@
import { BackupDatabaseNowResponse, DatabaseCheckIntegrityResponse } from "@triliumnext/commons";
-import { ValidationError } from "@triliumnext/core";
+import { becca_loader, ValidationError } from "@triliumnext/core";
import type { Request } from "express";
-import becca_loader from "../../becca/becca_loader.js";
import anonymizationService from "../../services/anonymization.js";
import backupService from "../../services/backup.js";
import consistencyChecksService from "../../services/consistency_checks.js";
diff --git a/apps/server/src/routes/api/import.ts b/apps/server/src/routes/api/import.ts
index 45e3f5f0be..a37124bbbb 100644
--- a/apps/server/src/routes/api/import.ts
+++ b/apps/server/src/routes/api/import.ts
@@ -1,9 +1,8 @@
-import { ValidationError } from "@triliumnext/core";
+import { becca_loader,ValidationError } from "@triliumnext/core";
import type { Request } from "express";
import path from "path";
import becca from "../../becca/becca.js";
-import beccaLoader from "../../becca/becca_loader.js";
import type BNote from "../../becca/entities/bnote.js";
import cls from "../../services/cls.js";
import enexImportService from "../../services/import/enex.js";
@@ -95,7 +94,7 @@ async function importNotesToBranch(req: Request) {
}
// import has deactivated note events so becca is not updated, instead we force it to reload
- beccaLoader.load();
+ becca_loader.load();
return note.getPojo();
}
diff --git a/apps/server/src/services/consistency_checks.ts b/apps/server/src/services/consistency_checks.ts
index 7b4ba72adf..887b8990d6 100644
--- a/apps/server/src/services/consistency_checks.ts
+++ b/apps/server/src/services/consistency_checks.ts
@@ -1,22 +1,23 @@
-"use strict";
-import sql from "./sql.js";
-import sqlInit from "./sql_init.js";
-import log from "./log.js";
-import ws from "./ws.js";
-import syncMutexService from "./sync_mutex.js";
+
+import type { BranchRow } from "@triliumnext/commons";
+import type { EntityChange } from "@triliumnext/commons";
+import { becca_loader } from "@triliumnext/core";
+
+import becca from "../becca/becca.js";
+import BBranch from "../becca/entities/bbranch.js";
+import eraseService from "../services/erase.js";
+import noteTypesService from "../services/note_types.js";
+import { hash as getHash, hashedBlobId, randomString } from "../services/utils.js";
import cls from "./cls.js";
import entityChangesService from "./entity_changes.js";
+import log from "./log.js";
import optionsService from "./options.js";
-import BBranch from "../becca/entities/bbranch.js";
-import becca from "../becca/becca.js";
-import { hash as getHash, hashedBlobId, randomString } from "../services/utils.js";
-import eraseService from "../services/erase.js";
import sanitizeAttributeName from "./sanitize_attribute_name.js";
-import noteTypesService from "../services/note_types.js";
-import type { BranchRow } from "@triliumnext/commons";
-import type { EntityChange } from "@triliumnext/commons";
-import becca_loader from "../becca/becca_loader.js";
+import sql from "./sql.js";
+import sqlInit from "./sql_init.js";
+import syncMutexService from "./sync_mutex.js";
+import ws from "./ws.js";
const noteTypes = noteTypesService.getNoteTypeNames();
class ConsistencyChecks {
@@ -84,11 +85,11 @@ class ConsistencyChecks {
}
return true;
- } else {
- logError(`Tree cycle detected at parent-child relationship: '${parentNoteId}' - '${noteId}', whole path: '${path}'`);
+ }
+ logError(`Tree cycle detected at parent-child relationship: '${parentNoteId}' - '${noteId}', whole path: '${path}'`);
- this.unrecoveredConsistencyErrors = true;
- }
+ this.unrecoveredConsistencyErrors = true;
+
} else {
const newPath = path.slice();
newPath.push(noteId);
@@ -186,7 +187,7 @@ class ConsistencyChecks {
if (note.getParentBranches().length === 0) {
const newBranch = new BBranch({
parentNoteId: "root",
- noteId: noteId,
+ noteId,
prefix: "recovered"
}).save();
@@ -349,7 +350,7 @@ class ConsistencyChecks {
if (this.autoFix) {
const branch = new BBranch({
parentNoteId: "root",
- noteId: noteId,
+ noteId,
prefix: "recovered"
}).save();
@@ -485,7 +486,7 @@ class ConsistencyChecks {
if (!blobAlreadyExists) {
// manually creating row since this can also affect deleted notes
sql.upsert("blobs", "blobId", {
- noteId: noteId,
+ noteId,
content: blankContent,
utcDateModified: fakeDate,
dateModified: fakeDate
@@ -496,7 +497,7 @@ class ConsistencyChecks {
entityChangesService.putEntityChange({
entityName: "blobs",
entityId: blobId,
- hash: hash,
+ hash,
isErased: false,
utcDateChanged: fakeDate,
isSynced: true
@@ -911,7 +912,7 @@ class ConsistencyChecks {
ws.sendMessageToAllClients({ type: "consistency-checks-failed" });
} else {
- log.info(`All consistency checks passed ` + (this.fixedIssues ? "after some fixes" : "with no errors detected") + ` (took ${elapsedTimeMs}ms)`);
+ log.info(`All consistency checks passed ${ this.fixedIssues ? "after some fixes" : "with no errors detected" } (took ${elapsedTimeMs}ms)`);
}
}
}
diff --git a/apps/server/src/services/sql_init.ts b/apps/server/src/services/sql_init.ts
index 1b69117602..c50b81acf3 100644
--- a/apps/server/src/services/sql_init.ts
+++ b/apps/server/src/services/sql_init.ts
@@ -89,7 +89,7 @@ async function createInitialDatabase(skipDemoDb?: boolean) {
// We have to import async since options init requires keyboard actions which require translations.
const optionsInitService = (await import("./options_init.js")).default;
- const becca_loader = (await import("../becca/becca_loader.js")).default;
+ const becca_loader = (await import("@triliumnext/core")).becca_loader;
sql.transactional(() => {
log.info("Creating database schema ...");
diff --git a/apps/server/src/services/sync.ts b/apps/server/src/services/sync.ts
index ef3bd6cba9..1ded101a34 100644
--- a/apps/server/src/services/sync.ts
+++ b/apps/server/src/services/sync.ts
@@ -1,27 +1,28 @@
-"use strict";
-import log from "./log.js";
-import sql from "./sql.js";
-import optionService from "./options.js";
-import { hmac, randomString, timeLimit } from "./utils.js";
-import instanceId from "./instance_id.js";
-import dateUtils from "./date_utils.js";
-import syncUpdateService from "./sync_update.js";
-import contentHashService from "./content_hash.js";
+
+import type { EntityChange, EntityChangeRecord, EntityRow } from "@triliumnext/commons";
+import { becca_loader } from "@triliumnext/core";
+
+import becca from "../becca/becca.js";
+import entityConstructor from "../becca/entity_constructor.js";
import appInfo from "./app_info.js";
-import syncOptions from "./sync_options.js";
-import syncMutexService from "./sync_mutex.js";
import cls from "./cls.js";
-import request from "./request.js";
-import ws from "./ws.js";
+import consistency_checks from "./consistency_checks.js";
+import contentHashService from "./content_hash.js";
+import dateUtils from "./date_utils.js";
import entityChangesService from "./entity_changes.js";
-import entityConstructor from "../becca/entity_constructor.js";
-import becca from "../becca/becca.js";
-import type { EntityChange, EntityChangeRecord, EntityRow } from "@triliumnext/commons";
+import instanceId from "./instance_id.js";
+import log from "./log.js";
+import optionService from "./options.js";
+import request from "./request.js";
import type { CookieJar, ExecOpts } from "./request_interface.js";
import setupService from "./setup.js";
-import consistency_checks from "./consistency_checks.js";
-import becca_loader from "../becca/becca_loader.js";
+import sql from "./sql.js";
+import syncMutexService from "./sync_mutex.js";
+import syncOptions from "./sync_options.js";
+import syncUpdateService from "./sync_update.js";
+import { hmac, randomString, timeLimit } from "./utils.js";
+import ws from "./ws.js";
let proxyToggle = true;
@@ -94,16 +95,16 @@ async function sync() {
success: false,
message: "No connection to sync server."
};
- } else {
- log.info(`Sync failed: '${e.message}', stack: ${e.stack}`);
+ }
+ log.info(`Sync failed: '${e.message}', stack: ${e.stack}`);
- ws.syncFailed();
+ ws.syncFailed();
- return {
- success: false,
- message: e.message
- };
- }
+ return {
+ success: false,
+ message: e.message
+ };
+
}
}
@@ -123,9 +124,9 @@ async function doLogin(): Promise<SyncContext> {
const syncContext: SyncContext = { cookieJar: {} };
const resp = await syncRequest<SyncResponse>(syncContext, "POST", "/api/login/sync", {
- timestamp: timestamp,
+ timestamp,
syncVersion: appInfo.syncVersion,
- hash: hash
+ hash
});
if (!resp) {
@@ -219,9 +220,9 @@ async function pushChanges(syncContext: SyncContext) {
lastSyncedPush = entityChange.id;
return false;
- } else {
- return true;
- }
+ }
+ return true;
+
});
if (filteredEntityChanges.length === 0 && lastSyncedPush) {
@@ -319,7 +320,7 @@ async function syncRequest<T extends {}>(syncContext: SyncContext, method: strin
method,
url: syncOptions.getSyncServerHost() + requestPath,
cookieJar: syncContext.cookieJar,
- timeout: timeout,
+ timeout,
paging: {
pageIndex,
pageCount,
@@ -340,33 +341,33 @@ function getEntityChangeRow(entityChange: EntityChange) {
if (entityName === "note_reordering") {
return sql.getMap("SELECT branchId, notePosition FROM branches WHERE parentNoteId = ? AND isDeleted = 0", [entityId]);
- } else {
- const primaryKey = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName;
+ }
+ const primaryKey = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName;
- if (!primaryKey) {
- throw new Error(`Unknown entity for entity change ${JSON.stringify(entityChange)}`);
- }
+ if (!primaryKey) {
+ throw new Error(`Unknown entity for entity change ${JSON.stringify(entityChange)}`);
+ }
- const entityRow = sql.getRow<EntityRow>(/*sql*/`SELECT * FROM ${entityName} WHERE ${primaryKey} = ?`, [entityId]);
+ const entityRow = sql.getRow<EntityRow>(/*sql*/`SELECT * FROM ${entityName} WHERE ${primaryKey} = ?`, [entityId]);
- if (!entityRow) {
- log.error(`Cannot find entity for entity change ${JSON.stringify(entityChange)}`);
- return null;
- }
+ if (!entityRow) {
+ log.error(`Cannot find entity for entity change ${JSON.stringify(entityChange)}`);
+ return null;
+ }
- if (entityName === "blobs" && entityRow.content !== null) {
- if (typeof entityRow.content === "string") {
- entityRow.content = Buffer.from(entityRow.content, "utf-8");
- }
+ if (entityName === "blobs" && entityRow.content !== null) {
+ if (typeof entityRow.content === "string") {
+ entityRow.content = Buffer.from(entityRow.content, "utf-8");
+ }
- if (entityRow.content) {
- entityRow.content = entityRow.content.toString("base64");
- }
+ if (entityRow.content) {
+ entityRow.content = entityRow.content.toString("base64");
}
+ }
- return entityRow;
- }
+ return entityRow;
+
}
function getEntityChangeRecords(entityChanges: EntityChange[]) {
diff --git a/packages/trilium-core/src/index.ts b/packages/trilium-core/src/index.ts
index c73eb6c80c..c5b9fa3173 100644
--- a/packages/trilium-core/src/index.ts
+++ b/packages/trilium-core/src/index.ts
@@ -16,6 +16,7 @@ export * from "./errors";
export type { CryptoProvider } from "./services/encryption/crypto";
export { default as becca } from "./becca/becca";
+export { default as becca_loader } from "./becca/becca_loader";
export { default as BAttachment } from "./becca/entities/battachment";
export { default as BAttribute } from "./becca/entities/battribute";
export { default as BBlob } from "./becca/entities/bblob";