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
chore(core): fix various type errors
Elian Doran0fc5b2e997fa
diff --git a/apps/server/src/etapi/metrics.ts b/apps/server/src/etapi/metrics.tsindex d460266472..05a5a41c98 100644--- a/apps/server/src/etapi/metrics.ts+++ b/apps/server/src/etapi/metrics.ts@@ -1,13 +1,14 @@-import type { Router, Request, Response, NextFunction } from "express";-import eu from "./etapi_utils.js";-import sql from "../services/sql.js";+import type { NextFunction,Request, Response, Router } from "express";+import appInfo from "../services/app_info.js";+import sql from "../services/sql.js";+import eu from "./etapi_utils.js";interface MetricsData {version: {app: string;db: number;- node: string;+ node?: string;sync: number;buildDate: string;buildRevision: string;@@ -45,7 +46,7 @@ function formatPrometheusMetrics(data: MetricsData): string {const lines: string[] = [];// Helper function to add a metric- const addMetric = (name: string, value: number | null, help: string, type: string = 'gauge', labels: Record<string, string> = {}) => {+ const addMetric = (name: string, value: number | null, help: string, type: string = 'gauge', labels: Record<string, string | undefined> = {}) => {if (value === null) return;lines.push(`# HELP ${name} ${help}`);@@ -233,8 +234,8 @@ function register(router: Router): void {} else if (format === 'prometheus') {const prometheusText = formatPrometheusMetrics(metrics);res.status(200)- .set('Content-Type', 'text/plain; version=0.0.4; charset=utf-8')- .send(prometheusText);+ .set('Content-Type', 'text/plain; version=0.0.4; charset=utf-8')+ .send(prometheusText);} else {throw new eu.EtapiError(400, "INVALID_FORMAT", "Supported formats: 'prometheus' (default), 'json'");}diff --git a/apps/server/src/routes/api/database.ts b/apps/server/src/routes/api/database.tsindex 2fe001a0b5..b73e25a22c 100644--- a/apps/server/src/routes/api/database.ts+++ b/apps/server/src/routes/api/database.ts@@ -1,5 +1,5 @@import { BackupDatabaseNowResponse, DatabaseCheckIntegrityResponse } from "@triliumnext/commons";-import { becca_loader, ValidationError } from "@triliumnext/core";+import { becca_loader, rebuildIntegrationTestDatabase as rebuildIntegrationTestDatabaseCore,ValidationError } from "@triliumnext/core";import type { Request } from "express";import anonymizationService from "../../services/anonymization.js";@@ -30,7 +30,7 @@ function findAndFixConsistencyIssues() {}async function rebuildIntegrationTestDatabase() {- sql.rebuildIntegrationTestDatabase();+ rebuildIntegrationTestDatabaseCore();sql_init.initializeDb();becca_loader.load();}diff --git a/apps/server/src/services/hidden_subtree.spec.ts b/apps/server/src/services/hidden_subtree.spec.tsindex dd3939155b..5282e5b525 100644--- a/apps/server/src/services/hidden_subtree.spec.ts+++ b/apps/server/src/services/hidden_subtree.spec.ts@@ -1,12 +1,11 @@import { deferred, LOCALES } from "@triliumnext/commons";+import { becca_loader, i18n } from "@triliumnext/core";import { beforeAll, describe, expect, it } from "vitest";import becca from "../becca/becca.js";-import becca_loader from "../becca/becca_loader.js";import branches from "./branches.js";import cls from "./cls.js";import hiddenSubtreeService from "./hidden_subtree.js";-import { changeLanguage } from "./i18n.js";import notes from "./notes.js";import sql_init from "./sql_init.js";@@ -141,7 +140,7 @@ describe("Hidden Subtree", () => {}try {- await changeLanguage(locale.id);+ await i18n.changeLanguage(locale.id);} catch (error) {done.reject(error);}diff --git a/packages/trilium-core/src/migrations/0233__migrate_geo_map_to_collection.spec.ts b/packages/trilium-core/src/migrations/0233__migrate_geo_map_to_collection.spec.tsindex 61a89584dc..6dfba236df 100644--- a/packages/trilium-core/src/migrations/0233__migrate_geo_map_to_collection.spec.ts+++ b/packages/trilium-core/src/migrations/0233__migrate_geo_map_to_collection.spec.ts@@ -1,6 +1,6 @@import { describe, expect, it, beforeEach } from "vitest";import * as cls from "../services/context.js";-import { getSql } from "../services/sql/index.js";+import { getSql, rebuildIntegrationTestDatabase } from "../services/sql/index.js";import becca from "../becca/becca.js";import becca_loader from "../becca/becca_loader.js";import migration from "./0233__migrate_geo_map_to_collection.js";@@ -23,7 +23,7 @@ describe("Migration 0233: Migrate geoMap to collection", () => {beforeEach(async () => {// Set up a clean in-memory database for each test- sql.rebuildIntegrationTestDatabase();+ rebuildIntegrationTestDatabase();await new Promise<void>((resolve) => {cls.getContext().init(() => {diff --git a/packages/trilium-core/src/services/backup.ts b/packages/trilium-core/src/services/backup.tsindex b596ccabe5..e229020f9d 100644--- a/packages/trilium-core/src/services/backup.ts+++ b/packages/trilium-core/src/services/backup.ts@@ -1,5 +1,5 @@export default {- backupNow() {+ backupNow(name: string) {console.warn("Backup not yet available.");}}diff --git a/packages/trilium-core/src/services/config.ts b/packages/trilium-core/src/services/config.tsindex 22ea820dbf..3a383a00b0 100644--- a/packages/trilium-core/src/services/config.ts+++ b/packages/trilium-core/src/services/config.ts@@ -2,5 +2,10 @@export default {General: {readOnly: false+ },+ Sync: {+ syncServerHost: "",+ syncServerTimeout: "120000",+ syncProxy: ""}};diff --git a/packages/trilium-core/src/services/image.ts b/packages/trilium-core/src/services/image.tsindex a40f0f0e25..835d388e35 100644--- a/packages/trilium-core/src/services/image.ts+++ b/packages/trilium-core/src/services/image.ts@@ -4,6 +4,7 @@ export default {return {attachmentId: null,+ title: ""};}}diff --git a/packages/trilium-core/src/services/script.ts b/packages/trilium-core/src/services/script.tsindex 83dc0272b6..a6a86754f6 100644--- a/packages/trilium-core/src/services/script.ts+++ b/packages/trilium-core/src/services/script.ts@@ -1,6 +1,6 @@import type BNote from "../becca/entities/bnote";-export function executeNoteNoException(script: unknown) {+export function executeNoteNoException(script: unknown, { originEntity: unknown }) {console.warn("Skipped script execution");}diff --git a/packages/trilium-core/src/services/search/services/search.spec.ts b/packages/trilium-core/src/services/search/services/search.spec.tsindex 5d0f1fa569..aaffa40aa8 100644--- a/packages/trilium-core/src/services/search/services/search.spec.ts+++ b/packages/trilium-core/src/services/search/services/search.spec.ts@@ -3,7 +3,7 @@ import searchService from "./search.js";import BNote from "../../../becca/entities/bnote.js";import BBranch from "../../../becca/entities/bbranch.js";import SearchContext from "../search_context.js";-import dateUtils from "../../date_utils.js";+import dateUtils from "../../utils/date.js";import becca from "../../../becca/becca.js";import { findNoteByTitle, note, NoteBuilder } from "../../../test/becca_mocking.js";diff --git a/packages/trilium-core/src/services/sql/index.ts b/packages/trilium-core/src/services/sql/index.tsindex c4dacd32c1..9b6516df8b 100644--- a/packages/trilium-core/src/services/sql/index.ts+++ b/packages/trilium-core/src/services/sql/index.ts@@ -14,6 +14,6 @@ export function getSql(): SqlService {return sql;}-export function rebuildIntegrationTestDatabase(path: string) {+export function rebuildIntegrationTestDatabase(path?: string) {throw new Error("Not implemented");}diff --git a/packages/trilium-core/src/services/tree.spec.ts b/packages/trilium-core/src/services/tree.spec.tsindex 7107152627..d705cba42e 100644--- a/packages/trilium-core/src/services/tree.spec.ts+++ b/packages/trilium-core/src/services/tree.spec.ts@@ -4,8 +4,8 @@ import becca from "../becca/becca.js";import BBranch from "../becca/entities/bbranch.js";import BNote from "../becca/entities/bnote.js";import tree from "./tree.js";-import cls from "./cls.js";import {buildNote} from "../test/becca_easy_mocking.js";+import { getContext } from "./context.js";describe("Tree", () => {let rootNote!: NoteBuilder;@@ -58,7 +58,7 @@ describe("Tree", () => {],"#sorted": "",});- cls.init(() => {+ getContext().init(() => {tree.sortNotesIfNeeded(note.noteId);});const orderedTitles = note.children.map((child) => child.title);@@ -85,7 +85,7 @@ describe("Tree", () => {// Sort a few times to ensure that the resulting order is the same.for (let i = 0; i < 5; i++) {- cls.init(() => {+ getContext().init(() => {tree.sortNotesIfNeeded(rootNote.note.noteId);});@@ -106,7 +106,7 @@ describe("Tree", () => {],"#sorted": ""});- cls.init(() => {+ getContext().init(() => {tree.sortNotesIfNeeded(note.noteId);});const orderedTitles = note.children.map((child) => child.title);@@ -126,7 +126,7 @@ describe("Tree", () => {"#sorted": "","#sortDirection": "desc"});- cls.init(() => {+ getContext().init(() => {tree.sortNotesIfNeeded(note.noteId);});const orderedTitles = note.children.map((child) => child.title);@@ -148,7 +148,7 @@ describe("Tree", () => {"#sorted": "","#sortFoldersFirst": ""});- cls.init(() => {+ getContext().init(() => {tree.sortNotesIfNeeded(note.noteId);});const orderedTitles = note.children.map((child) => child.title);@@ -169,7 +169,7 @@ describe("Tree", () => {"#sorted": "","#sortNatural": ""});- cls.init(() => {+ getContext().init(() => {tree.sortNotesIfNeeded(note.noteId);});const orderedTitles = note.children.map((child) => child.title);diff --git a/packages/trilium-core/src/services/utils/index.ts b/packages/trilium-core/src/services/utils/index.tsindex 57401fa512..ae0dcf7c62 100644--- a/packages/trilium-core/src/services/utils/index.ts+++ b/packages/trilium-core/src/services/utils/index.ts@@ -5,6 +5,7 @@ import mimeTypes from "mime-types";import escape from "escape-html";import unescape from "unescape";import path from "path";+import { NoteMeta } from "../../meta";// TODO: Implement platform detection.export const isElectron = false;diff --git a/packages/trilium-core/tsconfig.spec.json b/packages/trilium-core/tsconfig.spec.jsonindex 2819b04629..92448e8fa1 100644--- a/packages/trilium-core/tsconfig.spec.json+++ b/packages/trilium-core/tsconfig.spec.json@@ -20,7 +20,8 @@"src/**/*.spec.js","src/**/*.test.jsx","src/**/*.spec.jsx",- "src/**/*.d.ts"+ "src/**/*.d.ts",+ "src/**/*.json"],"references": [{