Skip to content

Commit

Permalink
Merge branch 'master' into matiss/strict-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
MatissJanis authored Jan 22, 2024
2 parents c12c56a + a4e97e0 commit 65e3a1b
Show file tree
Hide file tree
Showing 155 changed files with 1,592 additions and 643 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
packages/api/app/bundle.api.js
packages/api/dist
packages/api/@types
packages/api/migrations

packages/crdt/dist
Expand Down
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ module.exports = {
'@typescript-eslint/no-unused-vars': [
'warn',
{
args: 'none',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
Expand Down Expand Up @@ -165,6 +164,11 @@ module.exports = {
{ patterns: [...restrictedImportPatterns, ...restrictedImportColors] },
],

'@typescript-eslint/ban-ts-comment': [
'error',
{ 'ts-ignore': 'allow-with-description' },
],

// Rules disable during TS migration
'@typescript-eslint/no-var-requires': 'off',
'prefer-const': 'warn',
Expand Down
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ body:
required: true
validations:
required: true
- type: checkboxes
id: bank-sync-issue
attributes:
label: 'Is this related to GoCardless, Simplefin or another bank-sync provider?'
description: 'Most issues with bank-sync providers are due to a lack of a custom bank-mapper (i.e. payee or other fields not coming through). In such cases you can create a custom bank mapper in [actual-server](https://github.com/actualbudget/actual-server/blob/master/src/app-gocardless/README.md) repository. Other likely issue is misconfigured server - in which case please reach out via the [community Discord](https://discord.gg/pRYNYr4W5A) to get support.'
options:
- label: 'I have checked my server logs and could not see any errors there'
- label: 'I will be attaching my server logs to this issue'
- label: 'I will be attaching my client-side (browser) logs to this issue'
- label: 'I understand that this issue will be automatically closed if insufficient information is provided'
validations:
required: false
- type: textarea
id: what-happened
attributes:
Expand Down
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Support
url: https://discord.gg/pRYNYr4W5A
about: Need help with something? Perhaps having issues setting up bank-sync with GoCardless or SimpleFin? Reach out to the community on Discord.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
!data/.gitkeep
/data2
packages/api/dist
packages/api/@types
packages/crdt/dist
packages/desktop-electron/client-build
packages/desktop-electron/.electron-symbols
Expand Down
38 changes: 0 additions & 38 deletions packages/api/index.js

This file was deleted.

53 changes: 53 additions & 0 deletions packages/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type {
RequestInfo as FetchInfo,
RequestInit as FetchInit,
// @ts-ignore: false-positive commonjs module error on build until typescript 5.3
} from 'node-fetch'; // with { 'resolution-mode': 'import' };

// loot-core types
import type { InitConfig } from 'loot-core/server/main';

// @ts-ignore: bundle not available until we build it
// eslint-disable-next-line import/extensions
import * as bundle from './app/bundle.api.js';
import * as injected from './injected';
import { validateNodeVersion } from './validateNodeVersion';

let actualApp: null | typeof bundle.lib;
export const internal = bundle.lib;

// DEPRECATED: remove the next line in @actual-app/api v7
export * as methods from './methods';

export * from './methods';
export * as utils from './utils';

export async function init(config: InitConfig = {}) {
if (actualApp) {
return;
}

validateNodeVersion();

if (!globalThis.fetch) {
globalThis.fetch = (url: URL | RequestInfo, init?: RequestInit) => {
return import('node-fetch').then(({ default: fetch }) =>
fetch(url as unknown as FetchInfo, init as unknown as FetchInit),
) as unknown as Promise<Response>;
};
}

await bundle.init(config);
actualApp = bundle.lib;

injected.override(bundle.lib.send);
return bundle.lib;
}

export async function shutdown() {
if (actualApp) {
await actualApp.send('sync');
await actualApp.send('close-budget');
actualApp = null;
}
}
22 changes: 12 additions & 10 deletions packages/api/methods.js → packages/api/methods.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// @ts-strict-ignore
import type { Handlers } from 'loot-core/src/types/handlers';

import * as injected from './injected';

export { q } from './app/query';

function send(name, args) {
function send<K extends keyof Handlers, T extends Handlers[K]>(
name: K,
args?: Parameters<T>[0],
): Promise<Awaited<ReturnType<T>>> {
return injected.send(name, args);
}

Expand All @@ -21,7 +27,7 @@ export async function loadBudget(budgetId) {
return send('api/load-budget', { id: budgetId });
}

export async function downloadBudget(syncId, { password } = {}) {
export async function downloadBudget(syncId, { password }: { password? } = {}) {
return send('api/download-budget', { syncId, password });
}

Expand Down Expand Up @@ -79,10 +85,6 @@ export function getTransactions(accountId, startDate, endDate) {
return send('api/transactions-get', { accountId, startDate, endDate });
}

export function filterTransactions(accountId, text) {
return send('api/transactions-filter', { accountId, text });
}

export function updateTransaction(id, fields) {
return send('api/transaction-update', { id, fields });
}
Expand All @@ -95,15 +97,15 @@ export function getAccounts() {
return send('api/accounts-get');
}

export function createAccount(account, initialBalance) {
export function createAccount(account, initialBalance?) {
return send('api/account-create', { account, initialBalance });
}

export function updateAccount(id, fields) {
return send('api/account-update', { id, fields });
}

export function closeAccount(id, transferAccountId, transferCategoryId) {
export function closeAccount(id, transferAccountId?, transferCategoryId?) {
return send('api/account-close', {
id,
transferAccountId,
Expand All @@ -127,7 +129,7 @@ export function updateCategoryGroup(id, fields) {
return send('api/category-group-update', { id, fields });
}

export function deleteCategoryGroup(id, transferCategoryId) {
export function deleteCategoryGroup(id, transferCategoryId?) {
return send('api/category-group-delete', { id, transferCategoryId });
}

Expand All @@ -143,7 +145,7 @@ export function updateCategory(id, fields) {
return send('api/category-update', { id, fields });
}

export function deleteCategory(id, transferCategoryId) {
export function deleteCategory(id, transferCategoryId?) {
return send('api/category-delete', { id, transferCategoryId });
}

Expand Down
10 changes: 6 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
"node": ">=18.12.0"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"types": "@types/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build:app": "yarn workspace loot-core build:api",
"build:node": "tsc --p tsconfig.dist.json",
"build:node": "tsc --p tsconfig.dist.json && tsc-alias -p tsconfig.dist.json",
"build:migrations": "cp migrations/*.sql dist/migrations",
"build:default-db": "cp default-db.sqlite dist/",
"build": "rm -rf dist && yarn run build:app && yarn run build:node && yarn run build:migrations && yarn run build:default-db",
"test": "yarn run build:app && jest -c jest.config.js"
"build": "yarn run clean && yarn run build:app && yarn run build:node && yarn run build:migrations && yarn run build:default-db",
"test": "yarn run build:app && jest -c jest.config.js",
"clean": "rm -rf dist @types"
},
"dependencies": {
"better-sqlite3": "^9.2.2",
Expand All @@ -31,6 +32,7 @@
"@types/jest": "^27.5.0",
"@types/uuid": "^9.0.2",
"jest": "^27.0.0",
"tsc-alias": "^1.8.8",
"typescript": "^5.0.2"
}
}
8 changes: 6 additions & 2 deletions packages/api/tsconfig.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"moduleResolution": "Node16",
"noEmit": false,
"declaration": true,
"outDir": "dist"
"outDir": "dist",
"declarationDir": "@types",
"paths": {
"loot-core/*": ["./@types/loot-core/*"],
}
},
"include": ["."],
"exclude": ["dist"]
"exclude": ["**/node_modules/*", "dist", "@types"]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions packages/desktop-client/src/browser-preload.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ global.Actual = {
window.location.reload();
},

openFileDialog: async ({ filters = [], properties }) => {
openFileDialog: async ({ filters = [] }) => {
return new Promise(resolve => {
let createdElement = false;
// Attempt to reuse an already-created file input.
Expand Down Expand Up @@ -91,7 +91,7 @@ global.Actual = {
.uploadFile(filename, ev.target.result)
.then(() => resolve([filepath]));
};
reader.onerror = function (ev) {
reader.onerror = function () {
alert('Error reading file');
};
}
Expand All @@ -107,7 +107,7 @@ global.Actual = {
});
},

saveFile: (contents, defaultFilename, dialogTitle) => {
saveFile: (contents, defaultFilename) => {
const temp = document.createElement('a');
temp.style = 'display: none';
temp.download = defaultFilename;
Expand All @@ -121,9 +121,9 @@ global.Actual = {
openURLInBrowser: url => {
window.open(url, '_blank');
},
onEventFromMain: (type, handler) => {},
onEventFromMain: () => {},
applyAppUpdate: () => {},
updateAppMenu: isBudgetOpen => {},
updateAppMenu: () => {},

ipcConnect: () => {},
getServerSocket: async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/FatalError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function SharedArrayBufferOverride() {
>
<Checkbox
checked={understand}
onChange={_ => setUnderstand(!understand)}
onChange={() => setUnderstand(!understand)}
/>{' '}
I understand the risks, run Actual in the unsupported fallback mode
</label>
Expand Down
Loading

0 comments on commit 65e3a1b

Please sign in to comment.