Replies: 1 comment 2 replies
-
|
Hi @matshch! I'm Dosu and I’m helping the Trilium team. Since Trilium v0.48, backend scripts are required to be synchronous, which means you can't use To perform asynchronous operations like Here's a minimal example pattern: await api.runAsyncOnBackendWithManualTransactionHandling(async () => {
const response = await fetch("https://api.notion.com/v1/...");
const data = await response.json();
// Do Trilium API operations here
// If you want transactional safety, group related changes and handle errors
});If you want all-or-nothing changes, you'll need to implement your own rollback logic if something fails after partial changes. If you don't care about partial results, you can proceed without extra transaction handling, but be aware of the risks. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I'm writing an importer from Notion and having trouble using
fetchto get the data:fetchfails because Notion API does not set CORS headers, so it is a no-go,await fetch.When I just use
await fetchin a backend script, I get the next error: "await is only valid in async functions and the top level bodies of modules". I have found that since v0.48 your backend scripts are supposed to be synchronous, but I don't get how thefetchis supposed to be synchronous, looks like a gap in support there... I also can wrap this fetch call in an async function and call it, but I guess this will break transactional assumptions as the following code may execute after the main function has already ended.The only proper solution to call
fetchin a backend script that I see isapi.runAsyncOnBackendWithManualTransactionHandling(), but then I don't understand the required transaction management, is it OK to ignore it and just call Api methods as is if I don't care about partial results?Beta Was this translation helpful? Give feedback.
All reactions