chore(server): fix references to becca loader

This commit is contained in:
Elian Doran 2026-01-06 11:49:22 +02:00
parent f88ac5dfae
commit f9e22a9ba9
No known key found for this signature in database
9 changed files with 96 additions and 93 deletions

View File

@ -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;

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -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();
}

View File

@ -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 cls from "./cls.js";
import entityChangesService from "./entity_changes.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 { 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 sanitizeAttributeName from "./sanitize_attribute_name.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)`);
}
}
}

View File

@ -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 ...");

View File

@ -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 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 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 { 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 cls from "./cls.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 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)}`);
}
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 (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");
}
}
return entityRow;
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]);
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 (entityRow.content) {
entityRow.content = entityRow.content.toString("base64");
}
}
return entityRow;
}
function getEntityChangeRecords(entityChanges: EntityChange[]) {

View File

@ -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";