A local-first personal finance app
Extract sync related server handlers from main.ts to server/sync/app.ts (#4661)
Joel Jeremy Marquez1e685b993b8e
diff --git a/packages/loot-core/src/server/main.ts b/packages/loot-core/src/server/main.tsindex efe9da0aa8..c16ff8507e 100644--- a/packages/loot-core/src/server/main.ts+++ b/packages/loot-core/src/server/main.ts@@ -58,8 +58,8 @@ import {makeTestMessage,clearFullSyncTimeout,resetSync,- repairSync,} from './sync';+import { app as syncApp } from './sync/app';import * as syncMigrations from './sync/migrate';import { app as toolsApp } from './tools/app';import { app as transactionsApp } from './transactions/app';@@ -114,14 +114,6 @@ handlers['query'] = async function (query) {return aqlQuery(query);};-handlers['sync-reset'] = async function () {- return await resetSync();-};--handlers['sync-repair'] = async function () {- await repairSync();-};-// A user can only enable/change their key with the file loaded. This// will change in the future: during onboarding the user should be// able to enable encryption. (Imagine if they are importing data from@@ -445,10 +437,6 @@ handlers['set-server-url'] = async function ({ url, validate = true }) {return {};};-handlers['sync'] = async function () {- return fullSync();-};-handlers['validate-budget-name'] = async function ({ name }) {return validateBudgetName(name);};@@ -1106,6 +1094,7 @@ app.combine(accountsApp,payeesApp,spreadsheetApp,+ syncApp,);export function getDefaultDocumentDir() {diff --git a/packages/loot-core/src/server/sync/app.ts b/packages/loot-core/src/server/sync/app.tsnew file mode 100644index 0000000000..989c3e62fd--- /dev/null+++ b/packages/loot-core/src/server/sync/app.ts@@ -0,0 +1,29 @@+import { createApp } from '../app';++import { repairSync as _repairSync } from './repair';+import { resetSync as _resetSync } from './reset';++import { fullSync } from '.';++export type SyncHandlers = {+ sync: typeof sync;+ 'sync-reset': typeof resetSync;+ 'sync-repair': typeof repairSync;+};++export const app = createApp<SyncHandlers>();+app.method('sync', sync);+app.method('sync-reset', resetSync);+app.method('sync-repair', repairSync);++async function sync() {+ return await fullSync();+}++async function resetSync() {+ return await _resetSync();+}++async function repairSync() {+ await _repairSync();+}diff --git a/packages/loot-core/src/types/handlers.d.ts b/packages/loot-core/src/types/handlers.d.tsindex 920b0246ab..23246b2289 100644--- a/packages/loot-core/src/types/handlers.d.ts+++ b/packages/loot-core/src/types/handlers.d.ts@@ -10,6 +10,7 @@ import type { ReportsHandlers } from '../server/reports/app';import type { RulesHandlers } from '../server/rules/app';import type { SchedulesHandlers } from '../server/schedules/app';import type { SpreadsheetHandlers } from '../server/spreadsheet/app';+import type { SyncHandlers } from '../server/sync/app';import type { ToolsHandlers } from '../server/tools/app';import type { TransactionHandlers } from '../server/transactions/app';@@ -32,6 +33,7 @@ export interface HandlersToolsHandlers,AccountHandlers,PayeesHandlers,- SpreadsheetHandlers {}+ SpreadsheetHandlers,+ SyncHandlers {}export type HandlerFunctions = Handlers[keyof Handlers];diff --git a/packages/loot-core/src/types/server-handlers.d.ts b/packages/loot-core/src/types/server-handlers.d.tsindex e3c6e411c5..1fc2ffc271 100644--- a/packages/loot-core/src/types/server-handlers.d.ts+++ b/packages/loot-core/src/types/server-handlers.d.ts@@ -22,10 +22,6 @@ export interface ServerHandlers {// eslint-disable-next-line @typescript-eslint/no-explicit-anyquery: (query: Query) => Promise<{ data: any; dependencies: string[] }>;- 'sync-reset': () => Promise<{ error?: { reason: string; meta?: unknown } }>;-- 'sync-repair': () => Promise<unknown>;-'key-make': (arg: {password;}) => Promise<{ error?: { reason: string; meta?: unknown } }>;diff --git a/upcoming-release-notes/4661.md b/upcoming-release-notes/4661.mdnew file mode 100644index 0000000000..954729b1fe--- /dev/null+++ b/upcoming-release-notes/4661.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [joel-jeremy]+---++Extract sync related server handlers from main.ts to server/sync/app.ts