Merge pull request #43 from TriliumNext/feature/typescript_backend_7

Convert backend to TypeScript (71% -> 80%)
This commit is contained in:
Elian Doran
2024-04-15 21:51:00 +03:00
committed by GitHub
39 changed files with 615 additions and 444 deletions

View File

@@ -44,7 +44,7 @@ function subscribeBeccaLoader(eventTypes: EventType, listener: EventListener) {
}
}
function emit(eventType: string, data: any) {
function emit(eventType: string, data?: any) {
const listeners = eventListeners[eventType];
if (listeners) {

View File

@@ -55,7 +55,7 @@ interface Note {
let note: Partial<Note> = {};
let resource: Resource;
function importEnex(taskContext: TaskContext, file: File, parentNote: BNote) {
function importEnex(taskContext: TaskContext, file: File, parentNote: BNote): Promise<BNote> {
const saxStream = sax.createStream(true);
const rootNoteTitle = file.originalname.toLowerCase().endsWith(".enex")

View File

@@ -251,7 +251,7 @@ function createNewNote(params: NoteParams): {
});
}
function createNewNoteWithTarget(target: ("into" | "after"), targetBranchId: string, params: NoteParams) {
function createNewNoteWithTarget(target: ("into" | "after"), targetBranchId: string | undefined, params: NoteParams) {
if (!params.type) {
const parentNote = becca.notes[params.parentNoteId];
@@ -263,7 +263,7 @@ function createNewNoteWithTarget(target: ("into" | "after"), targetBranchId: str
if (target === 'into') {
return createNewNote(params);
}
else if (target === 'after') {
else if (target === 'after' && targetBranchId) {
const afterBranch = becca.branches[targetBranchId];
// not updating utcDateModified to avoid having to sync whole rows

View File

@@ -106,7 +106,7 @@ function execute(ctx: ScriptContext, script: string) {
return function () { return eval(`const apiContext = this;\r\n(${script}\r\n)()`); }.call(ctx);
}
function getParams(params: ScriptParams) {
function getParams(params?: ScriptParams) {
if (!params) {
return params;
}
@@ -121,7 +121,7 @@ function getParams(params: ScriptParams) {
}).join(",");
}
function getScriptBundleForFrontend(note: BNote, script: string, params: ScriptParams) {
function getScriptBundleForFrontend(note: BNote, script?: string, params?: ScriptParams) {
let overrideContent = null;
if (script) {

View File

@@ -110,7 +110,7 @@ function getSyncSeedOptions() {
];
}
module.exports = {
export = {
hasSyncServerSchemaAndSeed,
triggerSync,
sendSeedToSyncServer,

View File

@@ -166,7 +166,7 @@ function createScriptLauncher(parentNoteId: string, forceNoteId?: string) {
interface LauncherConfig {
parentNoteId: string;
launcherType: string;
noteId: string;
noteId?: string;
}
function createLauncher({ parentNoteId, launcherType, noteId }: LauncherConfig) {

View File

@@ -269,8 +269,8 @@ function transactional<T>(func: (statement: Statement) => T) {
}
}
function fillParamList(paramIds: string[], truncate = true) {
if (paramIds.length === 0) {
function fillParamList(paramIds: string[] | Set<string>, truncate = true) {
if ("length" in paramIds && paramIds.length === 0) {
return;
}

View File

@@ -66,7 +66,7 @@ class TaskContext {
});
}
taskSucceeded(result?: string) {
taskSucceeded(result?: string | Record<string, string | undefined>) {
ws.sendMessageToAllClients({
type: 'taskSucceeded',
taskId: this.taskId,

View File

@@ -41,7 +41,7 @@ interface Message {
taskType?: string | null;
message?: string;
reason?: string;
result?: string;
result?: string | Record<string, string | undefined>;
script?: string;
params?: any[];