Extract sync related server handlers from main.ts to server/sync/app.ts (#4661)

* Extract sync related server handlers from main.ts to server/sync/app.ts

* Release notes

* Revert async
This commit is contained in:
Joel Jeremy Marquez
2025-03-21 08:04:07 -07:00
committed by GitHub
parent 6b2d2420a5
commit 1e685b993b
5 changed files with 40 additions and 18 deletions

View File

@@ -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() {

View File

@@ -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();
}

View File

@@ -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 Handlers
ToolsHandlers,
AccountHandlers,
PayeesHandlers,
SpreadsheetHandlers {}
SpreadsheetHandlers,
SyncHandlers {}
export type HandlerFunctions = Handlers[keyof Handlers];

View File

@@ -22,10 +22,6 @@ export interface ServerHandlers {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
query: (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 } }>;