Skip to content

A local-first personal finance app

API: add missing TypeScript types (#6109)

Matiss Janis Aboltins6f17ee17ca32
diff --git a/packages/api/methods.test.ts b/packages/api/methods.test.ts
index b6fce1dca5..db7180e44b 100644
--- a/packages/api/methods.test.ts
+++ b/packages/api/methods.test.ts
@@ -1,7 +1,8 @@
-// @ts-strict-ignore
import * as fs from 'fs/promises';
import * as path from 'path';
+import { type RuleEntity } from 'loot-core/types/models';
+
import * as api from './index';
const budgetName = 'test-budget';
@@ -282,7 +283,7 @@ describe('API CRUD operations', () => {
expect(await api.getAccountBalance(accountId2)).toEqual(0);
await api.updateAccount(accountId1, { offbudget: false });
- await api.closeAccount(accountId1, accountId2, null);
+ await api.closeAccount(accountId1, accountId2);
await api.deleteAccount(accountId2);
// accounts successfully updated, and one of them deleted
@@ -505,7 +506,7 @@ describe('API CRUD operations', () => {
...rule,
stage: 'post',
conditionsOp: 'or',
- };
+ } satisfies RuleEntity;
expect(await api.updateRule(updatedRule)).toEqual(updatedRule);
expect(await api.getRules()).toEqual(
@@ -719,7 +720,7 @@ describe('API CRUD operations', () => {
// Test without notes
const transactionsWithoutNotes = [
- { date: '2023-11-03', imported_id: '11', amount: 100, notes: null },
+ { date: '2023-11-03', imported_id: '11', amount: 100 },
];
const addResultWithoutNotes = await api.addTransactions(
diff --git a/packages/api/methods.ts b/packages/api/methods.ts
index 1347356f81..a2f1ca3a47 100644
--- a/packages/api/methods.ts
+++ b/packages/api/methods.ts
@@ -1,6 +1,18 @@
-// @ts-strict-ignore
+import type {
+ APIAccountEntity,
+ APICategoryEntity,
+ APICategoryGroupEntity,
+ APIFileEntity,
+ APIPayeeEntity,
+ APIScheduleEntity,
+} from 'loot-core/server/api-models';
+import type { Query } from 'loot-core/shared/query';
import type { Handlers } from 'loot-core/types/handlers';
-import type { ImportTransactionEntity } from 'loot-core/types/models/import-transaction';
+import type {
+ ImportTransactionEntity,
+ RuleEntity,
+ TransactionEntity,
+} from 'loot-core/types/models';
import * as injected from './injected';
@@ -13,8 +25,11 @@ function send<K extends keyof Handlers, T extends Handlers[K]>(
return injected.send(name, args);
}
-export async function runImport(name, func) {
- await send('api/start-import', { budgetName: name });
+export async function runImport(
+ budgetName: APIFileEntity['name'],
+ func: () => Promise<void>,
+) {
+ await send('api/start-import', { budgetName });
try {
await func();
} catch (e) {
@@ -24,11 +39,14 @@ export async function runImport(name, func) {
await send('api/finish-import');
}
-export async function loadBudget(budgetId) {
+export async function loadBudget(budgetId: string) {
return send('api/load-budget', { id: budgetId });
}
-export async function downloadBudget(syncId, { password }: { password? } = {}) {
+export async function downloadBudget(
+ syncId: string,
+ { password }: { password?: string } = {},
+) {
return send('api/download-budget', { syncId, password });
}
@@ -40,11 +58,13 @@ export async function sync() {
return send('api/sync');
}
-export async function runBankSync(args?: { accountId: string }) {
+export async function runBankSync(args?: {
+ accountId: APIAccountEntity['id'];
+}) {
return send('api/bank-sync', args);
}
-export async function batchBudgetUpdates(func) {
+export async function batchBudgetUpdates(func: () => Promise<void>) {
await send('api/batch-budget-start');
try {
await func();
@@ -57,11 +77,11 @@ export async function batchBudgetUpdates(func) {
* @deprecated Please use `aqlQuery` instead.
* This function will be removed in a future release.
*/
-export function runQuery(query) {
+export function runQuery(query: Query) {
return send('api/query', { query: query.serialize() });
}
-export function aqlQuery(query) {
+export function aqlQuery(query: Query) {
return send('api/query', { query: query.serialize() });
}
@@ -69,22 +89,33 @@ export function getBudgetMonths() {
return send('api/budget-months');
}
-export function getBudgetMonth(month) {
+export function getBudgetMonth(month: string) {
return send('api/budget-month', { month });
}
-export function setBudgetAmount(month, categoryId, value) {
+export function setBudgetAmount(
+ month: string,
+ categoryId: APICategoryEntity['id'],
+ value: number,
+) {
return send('api/budget-set-amount', { month, categoryId, amount: value });
}
-export function setBudgetCarryover(month, categoryId, flag) {
+export function setBudgetCarryover(
+ month: string,
+ categoryId: APICategoryEntity['id'],
+ flag: boolean,
+) {
return send('api/budget-set-carryover', { month, categoryId, flag });
}
export function addTransactions(
- accountId,
- transactions,
- { learnCategories = false, runTransfers = false } = {},
+ accountId: APIAccountEntity['id'],
+ transactions: Omit<ImportTransactionEntity, 'account'>[],
+ {
+ learnCategories = false,
+ runTransfers = false,
+ }: { learnCategories?: boolean; runTransfers?: boolean } = {},
) {
return send('api/transactions-add', {
accountId,
@@ -100,7 +131,7 @@ export interface ImportTransactionsOpts {
}
export function importTransactions(
- accountId: string,
+ accountId: APIAccountEntity['id'],
transactions: ImportTransactionEntity[],
opts: ImportTransactionsOpts = {
defaultCleared: true,
@@ -115,15 +146,22 @@ export function importTransactions(
});
}
-export function getTransactions(accountId, startDate, endDate) {
+export function getTransactions(
+ accountId: APIAccountEntity['id'],
+ startDate: string,
+ endDate: string,
+) {
return send('api/transactions-get', { accountId, startDate, endDate });
}
-export function updateTransaction(id, fields) {
+export function updateTransaction(
+ id: TransactionEntity['id'],
+ fields: Partial<TransactionEntity>,
+) {
return send('api/transaction-update', { id, fields });
}
-export function deleteTransaction(id) {
+export function deleteTransaction(id: TransactionEntity['id']) {
return send('api/transaction-delete', { id });
}
@@ -131,15 +169,25 @@ export function getAccounts() {
return send('api/accounts-get');
}
-export function createAccount(account, initialBalance?) {
+export function createAccount(
+ account: Omit<APIAccountEntity, 'id'>,
+ initialBalance?: number,
+) {
return send('api/account-create', { account, initialBalance });
}
-export function updateAccount(id, fields) {
+export function updateAccount(
+ id: APIAccountEntity['id'],
+ fields: Partial<APIAccountEntity>,
+) {
return send('api/account-update', { id, fields });
}
-export function closeAccount(id, transferAccountId?, transferCategoryId?) {
+export function closeAccount(
+ id: APIAccountEntity['id'],
+ transferAccountId?: APIAccountEntity['id'],
+ transferCategoryId?: APICategoryEntity['id'],
+) {
return send('api/account-close', {
id,
transferAccountId,
@@ -147,15 +195,15 @@ export function closeAccount(id, transferAccountId?, transferCategoryId?) {
});
}
-export function reopenAccount(id) {
+export function reopenAccount(id: APIAccountEntity['id']) {
return send('api/account-reopen', { id });
}
-export function deleteAccount(id) {
+export function deleteAccount(id: APIAccountEntity['id']) {
return send('api/account-delete', { id });
}
-export function getAccountBalance(id, cutoff?) {
+export function getAccountBalance(id: APIAccountEntity['id'], cutoff?: Date) {
return send('api/account-balance', { id, cutoff });
}
@@ -163,15 +211,21 @@ export function getCategoryGroups() {
return send('api/category-groups-get');
}
-export function createCategoryGroup(group) {
+export function createCategoryGroup(group: Omit<APICategoryGroupEntity, 'id'>) {
return send('api/category-group-create', { group });
}
-export function updateCategoryGroup(id, fields) {
+export function updateCategoryGroup(
+ id: APICategoryGroupEntity['id'],
+ fields: Partial<APICategoryGroupEntity>,
+) {
return send('api/category-group-update', { id, fields });
}
-export function deleteCategoryGroup(id, transferCategoryId?) {
+export function deleteCategoryGroup(
+ id: APICategoryGroupEntity['id'],
+ transferCategoryId?: APICategoryEntity['id'],
+) {
return send('api/category-group-delete', { id, transferCategoryId });
}
@@ -179,15 +233,21 @@ export function getCategories() {
return send('api/categories-get', { grouped: false });
}
-export function createCategory(category) {
+export function createCategory(category: Omit<APICategoryEntity, 'id'>) {
return send('api/category-create', { category });
}
-export function updateCategory(id, fields) {
+export function updateCategory(
+ id: APICategoryEntity['id'],
+ fields: Partial<APICategoryEntity>,
+) {
return send('api/category-update', { id, fields });
}
-export function deleteCategory(id, transferCategoryId?) {
+export function deleteCategory(
+ id: APICategoryEntity['id'],
+ transferCategoryId?: APICategoryEntity['id'],
+) {
return send('api/category-delete', { id, transferCategoryId });
}
@@ -199,19 +259,25 @@ export function getPayees() {
return send('api/payees-get');
}
-export function createPayee(payee) {
+export function createPayee(payee: Omit<APIPayeeEntity, 'id'>) {
return send('api/payee-create', { payee });
}
-export function updatePayee(id, fields) {
+export function updatePayee(
+ id: APIPayeeEntity['id'],
+ fields: Partial<APIPayeeEntity>,
+) {
return send('api/payee-update', { id, fields });
}
-export function deletePayee(id) {
+export function deletePayee(id: APIPayeeEntity['id']) {
return send('api/payee-delete', { id });
}
-export function mergePayees(targetId, mergeIds) {
+export function mergePayees(
+ targetId: APIPayeeEntity['id'],
+ mergeIds: APIPayeeEntity['id'][],
+) {
return send('api/payees-merge', { targetId, mergeIds });
}
@@ -219,35 +285,39 @@ export function getRules() {
return send('api/rules-get');
}
-export function getPayeeRules(id) {
+export function getPayeeRules(id: RuleEntity['id']) {
return send('api/payee-rules-get', { id });
}
-export function createRule(rule) {
+export function createRule(rule: Omit<RuleEntity, 'id'>) {
return send('api/rule-create', { rule });
}
-export function updateRule(rule) {
+export function updateRule(rule: RuleEntity) {
return send('api/rule-update', { rule });
}
-export function deleteRule(id: string) {
+export function deleteRule(id: RuleEntity['id']) {
return send('api/rule-delete', id);
}
-export function holdBudgetForNextMonth(month, amount) {
+export function holdBudgetForNextMonth(month: string, amount: number) {
return send('api/budget-hold-for-next-month', { month, amount });
}
-export function resetBudgetHold(month) {
+export function resetBudgetHold(month: string) {
return send('api/budget-reset-hold', { month });
}
-export function createSchedule(schedule) {
+export function createSchedule(schedule: Omit<APIScheduleEntity, 'id'>) {
return send('api/schedule-create', schedule);
}
-export function updateSchedule(id, fields, resetNextDate?: boolean) {
+export function updateSchedule(
+ id: APIScheduleEntity['id'],
+ fields: Partial<APIScheduleEntity>,
+ resetNextDate?: boolean,
+) {
return send('api/schedule-update', {
id,
fields,
@@ -255,7 +325,7 @@ export function updateSchedule(id, fields, resetNextDate?: boolean) {
});
}
-export function deleteSchedule(scheduleId) {
+export function deleteSchedule(scheduleId: APIScheduleEntity['id']) {
return send('api/schedule-delete', scheduleId);
}
@@ -263,7 +333,10 @@ export function getSchedules() {
return send('api/schedules-get');
}
-export function getIDByName(type, name) {
+export function getIDByName(
+ type: 'accounts' | 'schedules' | 'categories' | 'payees',
+ name: string,
+) {
return send('api/get-id-by-name', { type, name });
}
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx
index fd8e2d3955..d3aa18af1e 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionListItem.tsx
@@ -336,7 +336,10 @@ function PayeeIcons({ transaction, transferAccount }: PayeeIconsProps) {
const isPreview = isPreviewId(id);
const schedule = schedules.find(s => s.id === scheduleId);
const isScheduleRecurring =
- schedule && schedule._date && !!schedule._date.frequency;
+ schedule &&
+ schedule._date &&
+ typeof schedule._date === 'object' &&
+ !!schedule._date.frequency;
if (isSchedulesLoading) {
return null;
diff --git a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
index 31c56f731c..10afa3235e 100644
--- a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
+++ b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx
@@ -277,9 +277,11 @@ function ScheduleRow({
<ScheduleAmountCell amount={schedule._amount} op={schedule._amountOp} />
{!minimal && (
<Field width={80} style={{ textAlign: 'center' }}>
- {schedule._date && schedule._date.frequency && (
- <SvgCheck style={{ width: 13, height: 13 }} />
- )}
+ {schedule._date &&
+ typeof schedule._date === 'object' &&
+ schedule._date.frequency && (
+ <SvgCheck style={{ width: 13, height: 13 }} />
+ )}
</Field>
)}
{!minimal && (
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
index d811478bcc..48216edeb1 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
@@ -771,7 +771,11 @@ function PayeeIcons({
return null;
}
- const recurring = schedule && schedule._date && !!schedule._date.frequency;
+ const recurring =
+ schedule &&
+ schedule._date &&
+ typeof schedule._date === 'object' &&
+ !!schedule._date.frequency;
const isDeposit = transaction.amount > 0;
return (
diff --git a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts
index 02f81a52e8..2b9e0744e1 100644
--- a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts
+++ b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts
@@ -82,7 +82,9 @@ export function useCategoryScheduleGoalTemplateIndicator({
return {
schedule,
scheduleStatus,
- isScheduleRecurring: !!schedule?._date?.frequency,
+ isScheduleRecurring: !!(
+ typeof schedule?._date === 'object' && schedule?._date?.frequency
+ ),
description,
};
}, [locale, month, scheduleStatuses, schedules, t]);
diff --git a/packages/loot-core/src/server/api-models.ts b/packages/loot-core/src/server/api-models.ts
index ee37c13a35..ea2b0fbb4f 100644
--- a/packages/loot-core/src/server/api-models.ts
+++ b/packages/loot-core/src/server/api-models.ts
@@ -5,15 +5,14 @@ import type {
CategoryGroupEntity,
PayeeEntity,
ScheduleEntity,
- RecurConfig,
} from '../types/models';
import { RemoteFile } from './cloud-storage';
import * as models from './models';
export type APIAccountEntity = Pick<AccountEntity, 'id' | 'name'> & {
- offbudget: boolean;
- closed: boolean;
+ offbudget?: boolean;
+ closed?: boolean;
};
export const accountModel = {
@@ -74,7 +73,7 @@ export type APICategoryGroupEntity = Pick<
CategoryGroupEntity,
'id' | 'name' | 'is_income' | 'hidden'
> & {
- categories: APICategoryEntity[];
+ categories?: APICategoryEntity[];
};
export const categoryGroupModel = {
@@ -92,7 +91,7 @@ export const categoryGroupModel = {
fromExternal(group: APICategoryGroupEntity) {
const result = { ...group } as unknown as CategoryGroupEntity;
- if ('categories' in group) {
+ if ('categories' in group && group.categories) {
result.categories = group.categories.map(categoryModel.fromExternal);
}
return result;
@@ -158,16 +157,18 @@ export const budgetModel = {
export type AmountOPType = 'is' | 'isapprox' | 'isbetween';
-export type APIScheduleEntity = Pick<ScheduleEntity, 'id' | 'name'> & {
- rule?: string; //All schedules has an associated underlying rule. not to be supplied iwth a new schedule
- next_date?: string; //Next occurence of a schedule. not to be supplied iwth a new schedule
- completed?: boolean; //not to be supplied iwth a new schedule
- posts_transaction: boolean; //Whethere the schedule should auto post transaction on your behalf. Default to false
- payee?: string | null; // Optional will default to null
- account?: string | null; // Optional will default to null
- amount: number | { num1: number; num2: number }; // Provide only 1 number except if the Amount
+export type APIScheduleEntity = Pick<
+ ScheduleEntity,
+ 'id' | 'name' | 'posts_transaction'
+> & {
+ rule?: ScheduleEntity['rule']; //All schedules has an associated underlying rule. not to be supplied iwth a new schedule
+ next_date?: ScheduleEntity['next_date']; //Next occurence of a schedule. not to be supplied iwth a new schedule
+ completed?: ScheduleEntity['completed']; //not to be supplied with a new schedule
+ payee?: ScheduleEntity['_payee']; // Optional will default to null
+ account?: ScheduleEntity['_account']; // Optional will default to null
+ amount?: ScheduleEntity['_amount']; // Provide only 1 number except if the Amount
amountOp: AmountOPType; // 'is' | 'isapprox' | 'isbetween'
- date: RecurConfig; // mandatory field in creating a schedule Mandatory field in creation
+ date: ScheduleEntity['_date']; // mandatory field in creating a schedule Mandatory field in creation
};
export const scheduleModel = {
@@ -189,6 +190,7 @@ export const scheduleModel = {
//just an update
fromExternal(schedule: APIScheduleEntity): ScheduleEntity {
+ const amount = schedule.amount ?? 0;
const result: ScheduleEntity = {
id: schedule.id,
name: schedule.name,
@@ -199,14 +201,14 @@ export const scheduleModel = {
tombstone: false,
_payee: String(schedule.payee),
_account: String(schedule.account),
- _amount: schedule.amount,
+ _amount: amount,
_amountOp: schedule.amountOp, // e.g. 'isapprox', 'is', etc.
_date: schedule.date,
_conditions: [
{ op: 'is', field: 'payee', value: String(schedule.payee) },
{ op: 'is', field: 'account', value: String(schedule.account) },
{ op: 'isapprox', field: 'date', value: schedule.date },
- { op: schedule.amountOp, field: 'amount', value: schedule.amount },
+ { op: schedule.amountOp, field: 'amount', value: amount },
],
_actions: [], // empty array, as you requested
};
diff --git a/packages/loot-core/src/server/api.ts b/packages/loot-core/src/server/api.ts
index cd7aa8a469..42ca8d1063 100644
--- a/packages/loot-core/src/server/api.ts
+++ b/packages/loot-core/src/server/api.ts
@@ -784,10 +784,10 @@ handlers['api/schedules-get'] = async function () {
};
handlers['api/schedule-create'] = withMutation(async function (
- schedule: APIScheduleEntity,
+ schedule: Omit<APIScheduleEntity, 'id'>,
) {
checkFileOpen();
- const internalSchedule = scheduleModel.fromExternal(schedule);
+ const internalSchedule = scheduleModel.fromExternal({ ...schedule, id: '' });
const partialSchedule = {
name: internalSchedule.name,
posts_transaction: internalSchedule.posts_transaction,
diff --git a/packages/loot-core/src/server/budget/app.ts b/packages/loot-core/src/server/budget/app.ts
index ce2e220bcd..c6583b6fb2 100644
--- a/packages/loot-core/src/server/budget/app.ts
+++ b/packages/loot-core/src/server/budget/app.ts
@@ -297,7 +297,7 @@ async function createCategory({
async function updateCategory(
category: CategoryEntity,
-): Promise<{ error?: { type: 'category-exists' } }> {
+): Promise<{ error: { type: 'category-exists' } } | object> {
try {
await db.updateCategory(
categoryModel.toDb({
diff --git a/packages/loot-core/src/server/importers/ynab4.ts b/packages/loot-core/src/server/importers/ynab4.ts
index 406ac63e0a..6f30dfa365 100644
--- a/packages/loot-core/src/server/importers/ynab4.ts
+++ b/packages/loot-core/src/server/importers/ynab4.ts
@@ -111,7 +111,6 @@ async function importPayees(
if (!payee.isTombstone) {
const id = await actual.createPayee({
name: payee.name,
- category: entityIdMap.get(payee.autoFillCategoryId) || null,
transfer_acct: entityIdMap.get(payee.targetAccountId) || null,
});
diff --git a/packages/loot-core/src/types/api-handlers.ts b/packages/loot-core/src/types/api-handlers.ts
index 36a0f28243..ccc43254a3 100644
--- a/packages/loot-core/src/types/api-handlers.ts
+++ b/packages/loot-core/src/types/api-handlers.ts
@@ -12,6 +12,7 @@ import type {
} from '../server/api-models';
import { BudgetFileHandlers } from '../server/budgetfiles/app';
import { type batchUpdateTransactions } from '../server/transactions';
+import type { QueryState } from '../shared/query';
import type {
ImportTransactionEntity,
@@ -22,9 +23,9 @@ import type {
} from './models';
export interface ApiHandlers {
- 'api/batch-budget-start': () => Promise<unknown>;
+ 'api/batch-budget-start': () => Promise<void>;
- 'api/batch-budget-end': () => Promise<unknown>;
+ 'api/batch-budget-end': () => Promise<void>;
'api/load-budget': (
...args: Parameters<BudgetFileHandlers['load-budget']>
@@ -43,11 +44,11 @@ export interface ApiHandlers {
'api/abort-import': () => Promise<void>;
- 'api/query': (arg: { query }) => Promise<unknown>;
+ 'api/query': (arg: { query: QueryState }) => Promise<unknown>;
'api/budget-months': () => Promise<string[]>;
- 'api/budget-month': (arg: { month }) => Promise<{
+ 'api/budget-month': (arg: { month: string }) => Promise<{
month: string;
incomeAvailable: number;
lastMonthOverspent: number;
@@ -89,110 +90,147 @@ export interface ApiHandlers {
}) => Promise<unknown>;
'api/transactions-import': (arg: {
- accountId;
+ accountId: APIAccountEntity['id'];
transactions: ImportTransactionEntity[];
- isPreview?;
+ isPreview?: boolean;
opts?: ImportTransactionsOpts;
}) => Promise<ImportTransactionsResult>;
'api/transactions-add': (arg: {
- accountId;
- transactions;
+ accountId: APIAccountEntity['id'];
+ transactions: Omit<ImportTransactionEntity, 'account'>[];
runTransfers?: boolean;
learnCategories?: boolean;
}) => Promise<'ok'>;
'api/transactions-get': (arg: {
- accountId?: string;
+ accountId?: APIAccountEntity['id'];
startDate?: string;
endDate?: string;
}) => Promise<TransactionEntity[]>;
'api/transaction-update': (arg: {
- id;
+ id: TransactionEntity['id'];
fields;
+ // TODO: fix me
+ // fields: Partial<TransactionEntity>;
}) => Promise<Awaited<ReturnType<typeof batchUpdateTransactions>>['updated']>;
'api/transaction-delete': (arg: {
- id;
+ id: TransactionEntity['id'];
}) => Promise<Awaited<ReturnType<typeof batchUpdateTransactions>>['deleted']>;
'api/sync': () => Promise<void>;
- 'api/bank-sync': (arg?: { accountId: string }) => Promise<void>;
+ 'api/bank-sync': (arg?: {
+ accountId: APIAccountEntity['id'];
+ }) => Promise<void>;
'api/accounts-get': () => Promise<APIAccountEntity[]>;
- 'api/account-create': (arg: { account; initialBalance? }) => Promise<string>;
+ 'api/account-create': (arg: {
+ account: Omit<APIAccountEntity, 'id'>;
+ initialBalance?: number;
+ }) => Promise<string>;
- 'api/account-update': (arg: { id; fields }) => Promise<void>;
+ 'api/account-update': (arg: {
+ id: APIAccountEntity['id'];
+ fields;
+ // TODO: fix me
+ // fields: Partial<APIAccountEntity>;
+ }) => Promise<void>;
'api/account-close': (arg: {
- id;
- transferAccountId;
- transferCategoryId;
- }) => Promise<unknown>;
+ id: APIAccountEntity['id'];
+ transferAccountId?: APIAccountEntity['id'];
+ transferCategoryId?: APICategoryEntity['id'];
+ }) => Promise<void>;
- 'api/account-reopen': (arg: { id }) => Promise<unknown>;
+ 'api/account-reopen': (arg: { id: APIAccountEntity['id'] }) => Promise<void>;
- 'api/account-delete': (arg: { id }) => Promise<unknown>;
+ 'api/account-delete': (arg: { id: APIAccountEntity['id'] }) => Promise<void>;
'api/account-balance': (arg: {
- id: string;
+ id: APIAccountEntity['id'];
cutoff?: Date;
}) => Promise<number>;
'api/categories-get': (arg: {
- grouped;
+ grouped?: boolean;
}) => Promise<Array<APICategoryGroupEntity | APICategoryEntity>>;
'api/category-groups-get': () => Promise<APICategoryGroupEntity[]>;
- 'api/category-group-create': (arg: { group }) => Promise<string>;
+ 'api/category-group-create': (arg: {
+ group: Omit<APICategoryGroupEntity, 'id'>;
+ }) => Promise<APICategoryGroupEntity['id']>;
- 'api/category-group-update': (arg: { id; fields }) => Promise<unknown>;
+ 'api/category-group-update': (arg: {
+ id: APICategoryGroupEntity['id'];
+ fields;
+ // TODO: fix me
+ // fields: Partial<APICategoryGroupEntity>;
+ }) => Promise<void>;
'api/category-group-delete': (arg: {
- id;
- transferCategoryId;
- }) => Promise<unknown>;
+ id: APICategoryGroupEntity['id'];
+ transferCategoryId?: APICategoryEntity['id'];
+ }) => Promise<void>;
- 'api/category-create': (arg: { category }) => Promise<string>;
+ 'api/category-create': (arg: {
+ category: Omit<APICategoryEntity, 'id'>;
+ }) => Promise<APICategoryEntity['id']>;
- 'api/category-update': (arg: { id; fields }) => Promise<unknown>;
+ 'api/category-update': (arg: {
+ id: APICategoryEntity['id'];
+ fields;
+ // TODO: fix me
+ // fields: Partial<APICategoryEntity>;
+ }) => Promise<{ error: { type: 'category-exists' } } | object>;
'api/category-delete': (arg: {
- id;
- transferCategoryId?;
- }) => Promise<{ error?: string }>;
+ id: APICategoryEntity['id'];
+ transferCategoryId?: APICategoryEntity['id'];
+ }) => Promise<
+ { error: 'no-categories' } | { error: 'category-type' } | object
+ >;
'api/payees-get': () => Promise<APIPayeeEntity[]>;
'api/common-payees-get': () => Promise<APIPayeeEntity[]>;
- 'api/payee-create': (arg: { payee }) => Promise<string>;
+ 'api/payee-create': (arg: {
+ payee: Omit<APIPayeeEntity, 'id'>;
+ }) => Promise<APIPayeeEntity['id']>;
- 'api/payee-update': (arg: { id; fields }) => Promise<unknown>;
+ 'api/payee-update': (arg: {
+ id: APIPayeeEntity['id'];
+ fields;
+ // TODO: fix me
+ // fields: Partial<APIPayeeEntity>;
+ }) => Promise<void>;
- 'api/payee-delete': (arg: { id }) => Promise<unknown>;
+ 'api/payee-delete': (arg: { id: APIPayeeEntity['id'] }) => Promise<void>;
'api/payees-merge': (arg: {
- targetId: string;
+ targetId: APIPayeeEntity['id'];
mergeIds: string[];
}) => Promise<void>;
'api/rules-get': () => Promise<RuleEntity[]>;
- 'api/payee-rules-get': (arg: { id: string }) => Promise<RuleEntity[]>;
+ 'api/payee-rules-get': (arg: {
+ id: APIPayeeEntity['id'];
+ }) => Promise<RuleEntity[]>;
'api/rule-create': (arg: { rule: NewRuleEntity }) => Promise<RuleEntity>;
'api/rule-update': (arg: { rule: RuleEntity }) => Promise<RuleEntity>;
- 'api/rule-delete': (id: string) => Promise<boolean>;
+ 'api/rule-delete': (id: RuleEntity['id']) => Promise<boolean>;
'api/schedule-create': (
- schedule: APIScheduleEntity,
+ schedule: Omit<APIScheduleEntity, 'id'>,
) => Promise<ScheduleEntity['id']>;
'api/schedule-update': (arg: {
@@ -209,6 +247,6 @@ export interface ApiHandlers {
name: string;
}) => Promise<string>;
'api/get-server-version': () => Promise<
- { error?: string } | { version: string }
+ { error: 'no-server' } | { error: 'network-failure' } | { version: string }
>;
}
diff --git a/packages/loot-core/src/types/models/schedule.ts b/packages/loot-core/src/types/models/schedule.ts
index 555ad2c3e1..f1a9850421 100644
--- a/packages/loot-core/src/types/models/schedule.ts
+++ b/packages/loot-core/src/types/models/schedule.ts
@@ -34,7 +34,7 @@ export interface ScheduleEntity {
_account: AccountEntity['id'];
_amount: number | { num1: number; num2: number };
_amountOp: string;
- _date: RecurConfig;
+ _date: RecurConfig | string;
_conditions: RuleConditionEntity[];
_actions: Array<{ op: unknown }>;
}
diff --git a/packages/loot-core/src/types/server-handlers.ts b/packages/loot-core/src/types/server-handlers.ts
index f37ad10383..e4dc233fbc 100644
--- a/packages/loot-core/src/types/server-handlers.ts
+++ b/packages/loot-core/src/types/server-handlers.ts
@@ -12,7 +12,9 @@ export interface ServerHandlers {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
query: (query: QueryState) => Promise<{ data: any; dependencies: string[] }>;
- 'get-server-version': () => Promise<{ error?: string } | { version: string }>;
+ 'get-server-version': () => Promise<
+ { error: 'no-server' } | { error: 'network-failure' } | { version: string }
+ >;
'get-server-url': () => Promise<string | null>;
diff --git a/packages/loot-core/typings/window.ts b/packages/loot-core/typings/window.ts
index e057dfce02..65db30ceef 100644
--- a/packages/loot-core/typings/window.ts
+++ b/packages/loot-core/typings/window.ts
@@ -51,4 +51,6 @@ declare global {
var Actual: Actual;
var IS_TESTING: boolean;
+
+ var currentMonth: string | null;
}
diff --git a/upcoming-release-notes/6109.md b/upcoming-release-notes/6109.md
new file mode 100644
index 0000000000..1fe5383cee
--- /dev/null
+++ b/upcoming-release-notes/6109.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+API: add missing TypeScript types