Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(scripting): rebind api.transactional to the SQL service (closes #10386)
Elian Doranc7d5f7229f6d
diff --git a/packages/trilium-core/src/services/backend_script_api.spec.ts b/packages/trilium-core/src/services/backend_script_api.spec.tsindex acca7a3250..eb622923d3 100644--- a/packages/trilium-core/src/services/backend_script_api.spec.ts+++ b/packages/trilium-core/src/services/backend_script_api.spec.ts@@ -33,6 +33,24 @@ describe("BackendScriptApi.log", () => {});});+describe("BackendScriptApi.transactional", () => {+ beforeEach(() => becca.reset());++ it("runs the callback inside a transaction and returns its result", () => {+ const startNote = buildNote({ type: "code", mime: "application/javascript;env=backend", content: "" });+ const api = new BackendScriptApi(startNote, { startNote });++ let executed = false;+ const result = api.transactional(() => {+ executed = true;+ return 42;+ });++ expect(executed).toBe(true);+ expect(result).toBe(42);+ });+});+describe("BackendScriptApi markdown conversion", () => {beforeEach(() => becca.reset());diff --git a/packages/trilium-core/src/services/backend_script_api.ts b/packages/trilium-core/src/services/backend_script_api.tsindex 3e21bbab5b..6c58ed9c49 100644--- a/packages/trilium-core/src/services/backend_script_api.ts+++ b/packages/trilium-core/src/services/backend_script_api.ts@@ -661,7 +661,7 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {this.sortNotes = (parentNoteId, sortConfig = {}) => treeService.sortNotes(parentNoteId, sortConfig.sortBy || "title", !!sortConfig.reverse, !!sortConfig.foldersFirst);this.setNoteToParent = treeService.setNoteToParent;- this.transactional = sql.transactional;+ this.transactional = (func) => sql.transactional(func);this.randomString = randomString;this.escapeHtml = escapeHtml;this.unescapeHtml = unescapeHtml;