Skip to content

Commit

Permalink
♻️ (typescript) hardening data entity types (#1680)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatissJanis authored Sep 27, 2023
1 parent 05f0df4 commit 9ca36f3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 17 deletions.
8 changes: 5 additions & 3 deletions packages/loot-core/src/mocks/budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { batchMessages, setSyncingMode } from '../server/sync';
import * as monthUtils from '../shared/months';
import q from '../shared/query';
import type {
CategoryEntity,
CategoryGroupEntity,
PayeeEntity,
TransactionEntity,
Expand Down Expand Up @@ -585,7 +586,7 @@ export async function createTestBudget(handlers) {
}),
);

let payees: PayeeEntity[] = [
let payees: Array<PayeeEntity & { bill?: boolean }> = [
{ name: 'Starting Balance' },
{ name: 'Kroger' },
{ name: 'Publix' },
Expand All @@ -608,7 +609,9 @@ export async function createTestBudget(handlers) {
}),
);

let categoryGroups: CategoryGroupEntity[] = [
let categoryGroups: Array<
CategoryGroupEntity & { categories: Omit<CategoryEntity, 'group'>[] }
> = [
{
name: 'Usual Expenses',
categories: [
Expand Down Expand Up @@ -650,7 +653,6 @@ export async function createTestBudget(handlers) {
isIncome: group.is_income ? 1 : 0,
});

// @ts-expect-error Missing proper type refinement
for (let category of group.categories) {
category.id = await handlers['category-create']({
...category,
Expand Down
6 changes: 2 additions & 4 deletions packages/loot-core/src/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ export function generateCategoryGroups(definition) {
}

function _generateTransaction(data): TransactionEntity {
const id = data.id || uuidv4();
return {
id: id,
id: data.id || uuidv4(),
amount: data.amount || Math.floor(random() * 10000 - 7000),
payee: data.payee || 'payed-to',
notes: 'Notes',
Expand All @@ -64,7 +63,6 @@ function _generateTransaction(data): TransactionEntity {
category: data.category,
sort_order: data.sort_order != null ? data.sort_order : 1,
cleared: false,
error: null,
};
}

Expand All @@ -76,7 +74,7 @@ export function generateTransaction(data, splitAmount?, showError = false) {

if (splitAmount) {
const parent = trans;
parent.isParent = true;
parent.is_parent = true;

result.push(
{
Expand Down
1 change: 0 additions & 1 deletion packages/loot-core/src/types/models/account.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export type AccountEntity = {
closed: 0 | 1;
sort_order: number;
tombstone: 0 | 1;
subtype: string | null; // TODO: remove?
} & (_SyncFields<true> | _SyncFields<false>);

type _SyncFields<T> = {
Expand Down
2 changes: 0 additions & 2 deletions packages/loot-core/src/types/models/category-group.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ export interface CategoryGroupEntity {
is_income?: boolean;
sort_order?: number;
tombstone?: boolean;
// TODO: remove once properly typed
[k: string]: unknown;
}
2 changes: 0 additions & 2 deletions packages/loot-core/src/types/models/payee.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ export interface PayeeEntity {
name: string;
transfer_acct?: AccountEntity;
tombstone?: boolean;
// TODO: remove once properly typed
[k: string]: unknown;
}
3 changes: 1 addition & 2 deletions packages/loot-core/src/types/models/rule.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { type ScheduleEntity } from './schedule';
export interface RuleEntity {
id: string;
stage: string;
conditions_op?: string;
conditionsOp?: string; // TODO: this should not be here.. figure out howto remove it
conditionsOp: 'any' | 'and';
conditions: RuleConditionEntity[];
actions: RuleActionEntity[];
tombstone?: boolean;
Expand Down
3 changes: 0 additions & 3 deletions packages/loot-core/src/types/models/transaction.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface TransactionEntity {
notes?: string;
date: string;
imported_id?: string;
error?: unknown;
imported_payee?: string;
starting_balance_flag?: boolean;
transfer_id?: string;
Expand All @@ -24,6 +23,4 @@ export interface TransactionEntity {
tombstone?: boolean;
schedule?: ScheduleEntity;
subtransactions?: TransactionEntity[];
// TODO: remove once properly typed
[k: string]: unknown;
}
6 changes: 6 additions & 0 deletions upcoming-release-notes/1680.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MatissJanis]
---

Typescript: hardening data entity types

0 comments on commit 9ca36f3

Please sign in to comment.