Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): fix types related to script execution

Elian Doran3a053d310473
diff --git a/apps/client/src/services/bundle.ts b/apps/client/src/services/bundle.ts
index 7cee01812b..d1c9e4532c 100644
--- a/apps/client/src/services/bundle.ts
+++ b/apps/client/src/services/bundle.ts
@@ -1,5 +1,7 @@
+import { ScriptParams } from "@triliumnext/commons";
import { h, VNode } from "preact";
+import FNote from "../entities/fnote.js";
import BasicWidget, { ReactWrappedWidget } from "../widgets/basic_widget.js";
import RightPanelWidget from "../widgets/right_panel_widget.js";
import type { Entity } from "./frontend_script_api.js";
@@ -26,7 +28,7 @@ type WithNoteId<T> = T & {
};
export type Widget = WithNoteId<(LegacyWidget | WidgetDefinitionWithType)>;
-async function getAndExecuteBundle(noteId: string, originEntity = null, script = null, params = null) {
+async function getAndExecuteBundle(noteId: string, originEntity: FNote | null = null, script: string | null = null, params: ScriptParams | null = null) {
const bundle = await server.post<Bundle>(`script/bundle/${noteId}`, {
script,
params
diff --git a/apps/client/src/services/ws.ts b/apps/client/src/services/ws.ts
index 6146fc9b7e..ac7d605043 100644
--- a/apps/client/src/services/ws.ts
+++ b/apps/client/src/services/ws.ts
@@ -88,12 +88,8 @@ export async function dispatchMessage(message: WebSocketMessage) {
} else if (messageType === "toast") {
toastService.showMessage(msg.message);
} else if (messageType === "execute-script") {
- // TODO: Remove after porting the file
- // @ts-ignore
- const bundleService = (await import("./bundle.js")).default as any;
- // TODO: Remove after porting the file
- // @ts-ignore
- const froca = (await import("./froca.js")).default as any;
+ const bundleService = (await import("./bundle.js")).default;
+ const froca = (await import("./froca.js")).default;
const originEntity = msg.originEntityId ? await froca.getNote(msg.originEntityId) : null;
bundleService.getAndExecuteBundle(msg.currentNoteId, originEntity, msg.script, msg.params);
diff --git a/apps/server/src/services/script.ts b/apps/server/src/services/script.ts
index 4b335f11d2..605d921f68 100644
--- a/apps/server/src/services/script.ts
+++ b/apps/server/src/services/script.ts
@@ -1,3 +1,4 @@
+import { ScriptParams } from "@triliumnext/commons";
import { binary_utils } from "@triliumnext/core";
import { transform } from "sucrase";
@@ -17,8 +18,6 @@ export interface Bundle {
allNoteIds?: string[];
}
-type ScriptParams = any[];
-
function executeNote(note: BNote, apiParams: ApiParams) {
if (!note.isJavaScript() || note.getScriptEnv() !== "backend" || !note.isContentAvailable()) {
log.info(`Cannot execute note ${note.noteId} "${note.title}", note must be of type "Code: JS backend"`);
diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.ts
index cb50e57a37..d07511c306 100644
--- a/packages/commons/src/lib/server_api.ts
+++ b/packages/commons/src/lib/server_api.ts
@@ -369,3 +369,5 @@ export type SetupSyncFromServerResponse = {
result: "failure";
error: string;
}
+
+export type ScriptParams = any[];