mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 02:30:42 +01:00
Merge pull request #43 from TriliumNext/feature/typescript_backend_7
Convert backend to TypeScript (71% -> 80%)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -110,7 +110,7 @@ function getSyncSeedOptions() {
|
||||
];
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export = {
|
||||
hasSyncServerSchemaAndSeed,
|
||||
triggerSync,
|
||||
sendSeedToSyncServer,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class TaskContext {
|
||||
});
|
||||
}
|
||||
|
||||
taskSucceeded(result?: string) {
|
||||
taskSucceeded(result?: string | Record<string, string | undefined>) {
|
||||
ws.sendMessageToAllClients({
|
||||
type: 'taskSucceeded',
|
||||
taskId: this.taskId,
|
||||
|
||||
@@ -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[];
|
||||
|
||||
Reference in New Issue
Block a user