migrate to typescript

This commit is contained in:
MaysWind
2024-12-29 14:24:37 +08:00
parent b638a73e4d
commit 2560a70e5e
171 changed files with 3402 additions and 2557 deletions
+80
View File
@@ -0,0 +1,80 @@
import type { TypeAndName } from './base.ts';
type AccountTypeName = 'SingleAccount' | 'MultiSubAccounts';
export class AccountType implements TypeAndName {
private static readonly allInstances: AccountType[] = [];
private static readonly allInstancesByTypeName: Record<string, AccountType> = {};
public static readonly SingleAccount = new AccountType(1, 'SingleAccount', 'Single Account');
public static readonly MultiSubAccounts = new AccountType(2, 'MultiSubAccounts', 'Multiple Sub-accounts');
public readonly type: number;
public readonly typeName: AccountTypeName;
public readonly name: string;
private constructor(type: number, typeName: AccountTypeName, name: string) {
this.type = type;
this.typeName = typeName;
this.name = name;
AccountType.allInstances.push(this);
AccountType.allInstancesByTypeName[typeName] = this;
}
public static values(): AccountType[] {
return AccountType.allInstances;
}
public static all(): Record<AccountTypeName, AccountType> {
return AccountType.allInstancesByTypeName;
}
}
type AccountCategoryTypeName = 'Cash' | 'CheckingAccount' | 'SavingsAccount' | 'CreditCard' | 'VirtualAccount' | 'DebtAccount' | 'Receivables' | 'CertificateOfDeposit' | 'InvestmentAccount';
export class AccountCategory implements TypeAndName {
private static readonly allInstances: AccountCategory[] = [];
private static readonly allInstancesByType: Record<number, AccountCategory> = {};
private static readonly allInstancesByTypeName: Record<string, AccountCategory> = {};
public static readonly Cash = new AccountCategory(1, 'Cash', 'Cash', '1');
public static readonly CheckingAccount = new AccountCategory(2, 'CheckingAccount', 'Checking Account', '100');
public static readonly SavingsAccount = new AccountCategory(8, 'SavingsAccount', 'Savings Account', '100');
public static readonly CreditCard = new AccountCategory(3, 'CreditCard', 'Credit Card', '100');
public static readonly VirtualAccount = new AccountCategory(4, 'VirtualAccount', 'Virtual Account', '500');
public static readonly DebtAccount = new AccountCategory(5, 'DebtAccount', 'Debt Account', '600');
public static readonly Receivables = new AccountCategory(6, 'Receivables', 'Receivables', '700');
public static readonly CertificateOfDeposit = new AccountCategory(9, 'CertificateOfDeposit', 'Certificate of Deposit', '110');
public static readonly InvestmentAccount = new AccountCategory(7, 'InvestmentAccount', 'Investment Account', '800');
public static readonly Default = AccountCategory.Cash;
public readonly type: number;
public readonly typeName: AccountCategoryTypeName;
public readonly name: string;
public readonly defaultAccountIconId: string;
private constructor(type: number, typeName: AccountCategoryTypeName, name: string, defaultAccountIconId: string) {
this.type = type;
this.typeName = typeName;
this.name = name;
this.defaultAccountIconId = defaultAccountIconId;
AccountCategory.allInstances.push(this);
AccountCategory.allInstancesByType[type] = this;
AccountCategory.allInstancesByTypeName[typeName] = this;
}
public static values(): AccountCategory[] {
return AccountCategory.allInstances;
}
public static all(): Record<AccountCategoryTypeName, AccountCategory> {
return AccountCategory.allInstancesByTypeName;
}
public static valueOf(type: number): AccountCategory {
return AccountCategory.allInstancesByType[type];
}
}
+9
View File
@@ -0,0 +1,9 @@
export interface TypeAndName {
readonly type: number;
readonly name: string;
}
export interface TypeAndDisplayName {
readonly type: number;
readonly displayName: string;
}
+5
View File
@@ -0,0 +1,5 @@
export enum CategoryType {
Income = 1,
Expense = 2,
Transfer = 3
}
+53
View File
@@ -0,0 +1,53 @@
import type { TypeAndName } from './base.ts';
export type ColorValue = string;
export interface ColorInfo {
readonly color: ColorValue;
}
export interface AmountColor {
readonly expenseAmountColor: ColorValue;
readonly incomeAmountColor: ColorValue;
}
export class PresetAmountColor implements TypeAndName {
private static readonly allInstances: PresetAmountColor[] = [];
private static readonly allInstancesByType: Record<number, PresetAmountColor> = {};
public static readonly SystemDefaultType: number = 0;
public static readonly Green = new PresetAmountColor(1, 'Green', '#009688', '#009688', 'expense-amount-color-green', 'income-amount-color-green');
public static readonly Red = new PresetAmountColor(2, 'Red', '#d43f3f', '#d43f3f', 'expense-amount-color-red', 'income-amount-color-red');
public static readonly Yellow = new PresetAmountColor(3, 'Yellow', '#e2b60a', '#e2b60a', 'expense-amount-color-yellow', 'income-amount-color-yellow');
public static readonly BlackOrWhite = new PresetAmountColor(4, 'Black or White', '#413935', '#fcf0e3', 'expense-amount-color-blackorwhite', 'income-amount-color-blackorwhite');
public static readonly DefaultExpenseColor = PresetAmountColor.Green;
public static readonly DefaultIncomeColor = PresetAmountColor.Red;
public readonly type: number;
public readonly name: string;
public readonly lightThemeColor: string;
public readonly darkThemeColor: string;
public readonly expenseClassName: string;
public readonly incomeClassName: string;
private constructor(type: number, name: string, lightThemeColor: string, darkThemeColor: string, expenseClassName: string, incomeClassName: string) {
this.type = type;
this.name = name;
this.lightThemeColor = lightThemeColor;
this.darkThemeColor = darkThemeColor;
this.expenseClassName = expenseClassName;
this.incomeClassName = incomeClassName;
PresetAmountColor.allInstances.push(this);
PresetAmountColor.allInstancesByType[type] = this;
}
public static values(): PresetAmountColor[] {
return PresetAmountColor.allInstances;
}
public static valueOf(type: number): PresetAmountColor {
return PresetAmountColor.allInstancesByType[type];
}
}
+98
View File
@@ -0,0 +1,98 @@
import type { TypeAndName } from './base.ts';
export enum CurrencyDisplaySymbol {
None = 0,
Symbol = 1,
Code = 2,
Unit = 3,
Name = 4
}
export enum CurrencyDisplayLocation {
BeforeAmount = 0,
AfterAmount = 1
}
export interface CurrencyPrependAndAppendText {
prependText?: string;
appendText?: string;
}
export class CurrencyDisplayType implements TypeAndName {
private static readonly allInstances: CurrencyDisplayType[] = [];
private static readonly allInstancesByType: Record<number, CurrencyDisplayType> = {};
private static readonly allInstancesByTypeName: Record<string, CurrencyDisplayType> = {};
public static readonly LanguageDefaultType = 0;
public static readonly None = new CurrencyDisplayType(1, 'None', 'None', 2, CurrencyDisplaySymbol.None, undefined, '');
public static readonly SymbolBeforeAmount = new CurrencyDisplayType(2, 'SymbolBeforeAmount', 'Currency Symbol', 2, CurrencyDisplaySymbol.Symbol, CurrencyDisplayLocation.BeforeAmount, ' ');
public static readonly SymbolAfterAmount = new CurrencyDisplayType(3, 'SymbolAfterAmount', 'Currency Symbol', 2, CurrencyDisplaySymbol.Symbol, CurrencyDisplayLocation.AfterAmount, ' ');
public static readonly SymbolBeforeAmountWithoutSpace = new CurrencyDisplayType(4, 'SymbolBeforeAmountWithoutSpace', 'Currency Symbol', 2, CurrencyDisplaySymbol.Symbol, CurrencyDisplayLocation.BeforeAmount, '');
public static readonly SymbolAfterAmountWithoutSpace = new CurrencyDisplayType(5, 'SymbolAfterAmountWithoutSpace', 'Currency Symbol', 2, CurrencyDisplaySymbol.Symbol, CurrencyDisplayLocation.AfterAmount, '');
public static readonly CodeBeforeAmount = new CurrencyDisplayType(6, 'CodeBeforeAmount', 'Currency Code', 2, CurrencyDisplaySymbol.Code, CurrencyDisplayLocation.BeforeAmount, ' ');
public static readonly CodeAfterAmount = new CurrencyDisplayType(7, 'CodeAfterAmount', 'Currency Code', 2, CurrencyDisplaySymbol.Code, CurrencyDisplayLocation.AfterAmount, ' ');
public static readonly UnitBeforeAmount = new CurrencyDisplayType(8, 'UnitBeforeAmount', 'Currency Unit', 2, CurrencyDisplaySymbol.Unit, CurrencyDisplayLocation.BeforeAmount, ' ');
public static readonly UnitAfterAmount = new CurrencyDisplayType(9, 'UnitAfterAmount', 'Currency Unit', 2, CurrencyDisplaySymbol.Unit, CurrencyDisplayLocation.AfterAmount, ' ');
public static readonly NameBeforeAmount = new CurrencyDisplayType(10, 'NameBeforeAmount', 'Currency Name', 2, CurrencyDisplaySymbol.Name, CurrencyDisplayLocation.BeforeAmount, ' ');
public static readonly NameAfterAmount = new CurrencyDisplayType(11, 'NameAfterAmount', 'Currency Name', 2, CurrencyDisplaySymbol.Name, CurrencyDisplayLocation.AfterAmount, ' ');
public static readonly Default = CurrencyDisplayType.SymbolBeforeAmount;
public readonly type: number;
public readonly typeName: string;
public readonly name: string;
public readonly fraction: number;
public readonly symbol: CurrencyDisplaySymbol;
public readonly location: CurrencyDisplayLocation | undefined;
public readonly separator: string;
private constructor(type: number, typeName: string, name: string, fraction: number, symbol: CurrencyDisplaySymbol, location: CurrencyDisplayLocation | undefined, separator: string) {
this.type = type;
this.typeName = typeName;
this.name = name;
this.fraction = fraction;
this.symbol = symbol;
this.location = location;
this.separator = separator;
CurrencyDisplayType.allInstances.push(this);
CurrencyDisplayType.allInstancesByType[type] = this;
CurrencyDisplayType.allInstancesByTypeName[typeName] = this;
}
public static values(): CurrencyDisplayType[] {
return CurrencyDisplayType.allInstances;
}
public static valueOf(type: number): CurrencyDisplayType {
return CurrencyDisplayType.allInstancesByType[type];
}
public static parse(typeName: string): CurrencyDisplayType {
return CurrencyDisplayType.allInstancesByTypeName[typeName];
}
}
export class CurrencySortingType implements TypeAndName {
private static readonly allInstances: CurrencySortingType[] = [];
public static readonly Name = new CurrencySortingType(0, 'Currency Name');
public static readonly CurrencyCode = new CurrencySortingType(1, 'Currency Code');
public static readonly ExchangeRate = new CurrencySortingType(2, 'Exchange Rate');
public static readonly Default = CurrencySortingType.Name;
public readonly type: number;
public readonly name: string;
private constructor(type: number, name: string) {
this.type = type;
this.name = name;
CurrencySortingType.allInstances.push(this);
}
public static values(): CurrencySortingType[] {
return CurrencySortingType.allInstances;
}
}
+20
View File
@@ -0,0 +1,20 @@
export class MeridiemIndicator {
private static readonly allInstances: MeridiemIndicator[] = [];
public static readonly AM = new MeridiemIndicator(0, 'AM');
public static readonly PM = new MeridiemIndicator(1, 'PM');
public readonly type: number;
public readonly value: string;
private constructor(type: number, value: string) {
this.type = type;
this.value = value;
MeridiemIndicator.allInstances.push(this);
}
public static values(): MeridiemIndicator[] {
return MeridiemIndicator.allInstances;
}
}
+30
View File
@@ -0,0 +1,30 @@
export class FontSize {
private static readonly allInstances: FontSize[] = [];
public static readonly Small = new FontSize(0, 'font-size-small');
public static readonly Default = new FontSize(1, 'font-size-default');
public static readonly Large = new FontSize(2, 'font-size-large');
public static readonly XLarge = new FontSize(3, 'font-size-x-large');
public static readonly XXLarge = new FontSize(4, 'font-size-xx-large');
public static readonly XXXLarge = new FontSize(5, 'font-size-xxx-large');
public static readonly XXXXLarge = new FontSize(6, 'font-size-xxxx-large');
public static readonly MinimumFontSize = FontSize.Small;
public static readonly MaximumFontSize = FontSize.XXXXLarge;
public readonly type: number;
public readonly className: string;
private constructor(type: number, className: string) {
this.type = type;
this.className = className;
FontSize.allInstances.push(this);
}
public static values(): FontSize[] {
return FontSize.allInstances;
}
}
export const FONT_SIZE_PREVIEW_CLASSNAME_PREFIX: string = 'preview-';
+10
View File
@@ -0,0 +1,10 @@
export type LineAwesomeIconClassName = string;
export interface IconInfo {
readonly icon: LineAwesomeIconClassName;
}
export interface IconInfoWithId {
readonly id: string;
readonly icon: LineAwesomeIconClassName;
}
+72
View File
@@ -0,0 +1,72 @@
import type { TypeAndName } from './base.ts';
type TemplateTypeName = 'Normal' | 'Schedule';
export class TemplateType implements TypeAndName {
private static readonly allInstances: TemplateType[] = [];
private static readonly allInstancesByType: Record<number, TemplateType> = {};
private static readonly allInstancesByTypeName: Record<string, TemplateType> = {};
public static readonly Normal = new TemplateType(1, 'Normal');
public static readonly Schedule = new TemplateType(2, 'Schedule');
public readonly type: number;
public readonly name: TemplateTypeName;
private constructor(type: number, name: TemplateTypeName) {
this.type = type;
this.name = name;
TemplateType.allInstances.push(this);
TemplateType.allInstancesByType[type] = this;
TemplateType.allInstancesByTypeName[name] = this;
}
public static values(): TemplateType[] {
return TemplateType.allInstances;
}
public static all(): Record<TemplateTypeName, TemplateType> {
return TemplateType.allInstancesByTypeName;
}
public static valueOf(type: number): TemplateType {
return TemplateType.allInstancesByType[type];
}
}
type ScheduledTemplateFrequencyTypeName = 'Disabled' | 'Weekly' | 'Monthly';
export class ScheduledTemplateFrequencyType implements TypeAndName {
private static readonly allInstances: ScheduledTemplateFrequencyType[] = [];
private static readonly allInstancesByType: Record<number, ScheduledTemplateFrequencyType> = {};
private static readonly allInstancesByTypeName: Record<string, ScheduledTemplateFrequencyType> = {};
public static readonly Disabled = new ScheduledTemplateFrequencyType(0, 'Disabled');
public static readonly Weekly = new ScheduledTemplateFrequencyType(1, 'Weekly');
public static readonly Monthly = new ScheduledTemplateFrequencyType(2, 'Monthly');
public readonly type: number;
public readonly name: ScheduledTemplateFrequencyTypeName;
private constructor(type: number, name: ScheduledTemplateFrequencyTypeName) {
this.type = type;
this.name = name;
ScheduledTemplateFrequencyType.allInstances.push(this);
ScheduledTemplateFrequencyType.allInstancesByType[type] = this;
ScheduledTemplateFrequencyType.allInstancesByTypeName[name] = this;
}
public static values(): ScheduledTemplateFrequencyType[] {
return ScheduledTemplateFrequencyType.allInstances;
}
public static all(): Record<ScheduledTemplateFrequencyTypeName, ScheduledTemplateFrequencyType> {
return ScheduledTemplateFrequencyType.allInstancesByTypeName;
}
public static valueOf(type: number): ScheduledTemplateFrequencyType {
return ScheduledTemplateFrequencyType.allInstancesByType[type];
}
}
+4
View File
@@ -0,0 +1,4 @@
export enum ThemeType {
Light = 'light',
Dark = 'dark'
}
+16
View File
@@ -0,0 +1,16 @@
import type { TypeAndName } from './base.ts';
export class TimezoneTypeForStatistics implements TypeAndName {
public static readonly ApplicationTimezone = new TimezoneTypeForStatistics(0, 'Application Timezone');
public static readonly TransactionTimezone = new TimezoneTypeForStatistics(1, 'Transaction Timezone');
public static readonly Default = TimezoneTypeForStatistics.ApplicationTimezone;
public readonly type: number;
public readonly name: string;
private constructor(type: number, name: string) {
this.type = type;
this.name = name;
}
}
+59
View File
@@ -0,0 +1,59 @@
import type { TypeAndName } from './base.ts';
export enum TransactionType {
ModifyBalance = 1,
Income = 2,
Expense = 3,
Transfer = 4
}
export class TransactionEditScopeType implements TypeAndName {
private static readonly allInstances: TransactionEditScopeType[] = [];
public static readonly None = new TransactionEditScopeType(0, 'None');
public static readonly All = new TransactionEditScopeType(1, 'All');
public static readonly TodayOrLater = new TransactionEditScopeType(2, 'Today or later');
public static readonly Recent24HoursOrLater = new TransactionEditScopeType(3, 'Recent 24 hours or later');
public static readonly ThisWeekOrLater = new TransactionEditScopeType(4, 'This week or later');
public static readonly ThisMonthOrLater = new TransactionEditScopeType(5, 'This month or later');
public static readonly ThisYearOrLater = new TransactionEditScopeType(6, 'This year or later');
public readonly type: number;
public readonly name: string;
private constructor(type: number, name: string) {
this.type = type;
this.name = name;
TransactionEditScopeType.allInstances.push(this);
}
public static values(): TransactionEditScopeType[] {
return TransactionEditScopeType.allInstances;
}
}
export class TransactionTagFilterType implements TypeAndName {
private static readonly allInstances: TransactionTagFilterType[] = [];
public static readonly HasAny = new TransactionTagFilterType(0, 'With Any Selected Tags');
public static readonly HasAll = new TransactionTagFilterType(1, 'With All Selected Tags');
public static readonly NotHasAny = new TransactionTagFilterType(2, 'Without Any Selected Tags');
public static readonly NotHasAll = new TransactionTagFilterType(3, 'Without All Selected Tags');
public static readonly Default = TransactionTagFilterType.HasAny;
public readonly type: number;
public readonly name: string;
private constructor(type: number, name: string) {
this.type = type;
this.name = name;
TransactionTagFilterType.allInstances.push(this);
}
public static values(): TransactionTagFilterType[] {
return TransactionTagFilterType.allInstances;
}
}