@actual-app/api 5.1.2 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/bundle.api.d.ts +3 -0
- package/dist/app/bundle.api.js +65599 -0
- package/dist/app/query.d.ts +19 -0
- package/dist/app/query.js +88 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +59 -0
- package/dist/injected.d.ts +2 -0
- package/dist/injected.js +8 -0
- package/dist/methods.d.ts +35 -0
- package/dist/methods.js +181 -0
- package/dist/migrations/1632571489012_remove_cache.d.ts +1 -0
- package/dist/migrations/1632571489012_remove_cache.js +103 -0
- package/dist/migrations/1681115033845_add_schedule_name.sql +5 -0
- package/dist/migrations/1682974838138_remove_payee_rules.sql +5 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +31 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +11 -0
- package/package.json +12 -10
- package/app/bundle.api.js +0 -68617
- package/app/bundle.api.js.map +0 -1
- package/app/query.js +0 -104
- package/index.js +0 -34
- package/injected.js +0 -5
- package/methods.js +0 -212
- package/migrations/1632571489012_remove_cache.js +0 -135
- package/utils.js +0 -9
- /package/{default-db.sqlite → dist/default-db.sqlite} +0 -0
- /package/{migrations → dist/migrations}/1548957970627_remove-db-version.sql +0 -0
- /package/{migrations → dist/migrations}/1550601598648_payees.sql +0 -0
- /package/{migrations → dist/migrations}/1555786194328_remove_category_group_unique.sql +0 -0
- /package/{migrations → dist/migrations}/1561751833510_indexes.sql +0 -0
- /package/{migrations → dist/migrations}/1567699552727_budget.sql +0 -0
- /package/{migrations → dist/migrations}/1582384163573_cleared.sql +0 -0
- /package/{migrations → dist/migrations}/1597756566448_rules.sql +0 -0
- /package/{migrations → dist/migrations}/1608652596043_parent_field.sql +0 -0
- /package/{migrations → dist/migrations}/1608652596044_trans_views.sql +0 -0
- /package/{migrations → dist/migrations}/1612625548236_optimize.sql +0 -0
- /package/{migrations → dist/migrations}/1614782639336_trans_views2.sql +0 -0
- /package/{migrations → dist/migrations}/1615745967948_meta.sql +0 -0
- /package/{migrations → dist/migrations}/1616167010796_accounts_order.sql +0 -0
- /package/{migrations → dist/migrations}/1618975177358_schedules.sql +0 -0
- /package/{migrations → dist/migrations}/1679728867040_rules_conditions.sql +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default function q(table: any): Query;
|
|
2
|
+
declare class Query {
|
|
3
|
+
constructor(state: any);
|
|
4
|
+
state: any;
|
|
5
|
+
filter(expr: any): Query;
|
|
6
|
+
unfilter(exprs: any): Query;
|
|
7
|
+
select(exprs?: any[]): Query;
|
|
8
|
+
calculate(expr: any): Query;
|
|
9
|
+
groupBy(exprs: any): Query;
|
|
10
|
+
orderBy(exprs: any): Query;
|
|
11
|
+
limit(num: any): Query;
|
|
12
|
+
offset(num: any): Query;
|
|
13
|
+
raw(): Query;
|
|
14
|
+
withDead(): Query;
|
|
15
|
+
withoutValidatedRefs(): Query;
|
|
16
|
+
options(opts: any): Query;
|
|
17
|
+
serialize(): any;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Query {
|
|
4
|
+
constructor(state) {
|
|
5
|
+
this.state = {
|
|
6
|
+
filterExpressions: state.filterExpressions || [],
|
|
7
|
+
selectExpressions: state.selectExpressions || [],
|
|
8
|
+
groupExpressions: state.groupExpressions || [],
|
|
9
|
+
orderExpressions: state.orderExpressions || [],
|
|
10
|
+
calculation: false,
|
|
11
|
+
rawMode: false,
|
|
12
|
+
withDead: false,
|
|
13
|
+
validateRefs: true,
|
|
14
|
+
limit: null,
|
|
15
|
+
offset: null,
|
|
16
|
+
...state,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
filter(expr) {
|
|
20
|
+
return new Query({
|
|
21
|
+
...this.state,
|
|
22
|
+
filterExpressions: [...this.state.filterExpressions, expr],
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
unfilter(exprs) {
|
|
26
|
+
let exprSet = new Set(exprs);
|
|
27
|
+
return new Query({
|
|
28
|
+
...this.state,
|
|
29
|
+
filterExpressions: this.state.filterExpressions.filter(expr => !exprSet.has(Object.keys(expr)[0])),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
select(exprs = []) {
|
|
33
|
+
if (!Array.isArray(exprs)) {
|
|
34
|
+
exprs = [exprs];
|
|
35
|
+
}
|
|
36
|
+
let query = new Query({ ...this.state, selectExpressions: exprs });
|
|
37
|
+
query.state.calculation = false;
|
|
38
|
+
return query;
|
|
39
|
+
}
|
|
40
|
+
calculate(expr) {
|
|
41
|
+
let query = this.select({ result: expr });
|
|
42
|
+
query.state.calculation = true;
|
|
43
|
+
return query;
|
|
44
|
+
}
|
|
45
|
+
groupBy(exprs) {
|
|
46
|
+
if (!Array.isArray(exprs)) {
|
|
47
|
+
exprs = [exprs];
|
|
48
|
+
}
|
|
49
|
+
return new Query({
|
|
50
|
+
...this.state,
|
|
51
|
+
groupExpressions: [...this.state.groupExpressions, ...exprs],
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
orderBy(exprs) {
|
|
55
|
+
if (!Array.isArray(exprs)) {
|
|
56
|
+
exprs = [exprs];
|
|
57
|
+
}
|
|
58
|
+
return new Query({
|
|
59
|
+
...this.state,
|
|
60
|
+
orderExpressions: [...this.state.orderExpressions, ...exprs],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
limit(num) {
|
|
64
|
+
return new Query({ ...this.state, limit: num });
|
|
65
|
+
}
|
|
66
|
+
offset(num) {
|
|
67
|
+
return new Query({ ...this.state, offset: num });
|
|
68
|
+
}
|
|
69
|
+
raw() {
|
|
70
|
+
return new Query({ ...this.state, rawMode: true });
|
|
71
|
+
}
|
|
72
|
+
withDead() {
|
|
73
|
+
return new Query({ ...this.state, withDead: true });
|
|
74
|
+
}
|
|
75
|
+
withoutValidatedRefs() {
|
|
76
|
+
return new Query({ ...this.state, validateRefs: false });
|
|
77
|
+
}
|
|
78
|
+
options(opts) {
|
|
79
|
+
return new Query({ ...this.state, tableOptions: opts });
|
|
80
|
+
}
|
|
81
|
+
serialize() {
|
|
82
|
+
return this.state;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function q(table) {
|
|
86
|
+
return new Query({ table });
|
|
87
|
+
}
|
|
88
|
+
exports.default = q;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.shutdown = exports.init = exports.utils = exports.methods = exports.internal = void 0;
|
|
33
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
34
|
+
const bundle = __importStar(require("./app/bundle.api"));
|
|
35
|
+
const injected = __importStar(require("./injected"));
|
|
36
|
+
let actualApp;
|
|
37
|
+
exports.internal = bundle.lib;
|
|
38
|
+
// DEPRECATED: remove the next line in @actual-app/api v7
|
|
39
|
+
exports.methods = __importStar(require("./methods"));
|
|
40
|
+
__exportStar(require("./methods"), exports);
|
|
41
|
+
exports.utils = __importStar(require("./utils"));
|
|
42
|
+
async function init(config = {}) {
|
|
43
|
+
if (actualApp) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
global.fetch = node_fetch_1.default;
|
|
47
|
+
await bundle.init(config);
|
|
48
|
+
actualApp = bundle.lib;
|
|
49
|
+
injected.override(bundle.lib.send);
|
|
50
|
+
return bundle.lib;
|
|
51
|
+
}
|
|
52
|
+
exports.init = init;
|
|
53
|
+
async function shutdown() {
|
|
54
|
+
if (actualApp) {
|
|
55
|
+
await actualApp.send('close-budget');
|
|
56
|
+
actualApp = null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.shutdown = shutdown;
|
package/dist/injected.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO: comment on why it works this way
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.override = exports.send = void 0;
|
|
5
|
+
function override(sendImplementation) {
|
|
6
|
+
exports.send = sendImplementation;
|
|
7
|
+
}
|
|
8
|
+
exports.override = override;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function runImport(name: any, func: any): Promise<void>;
|
|
2
|
+
export function loadBudget(budgetId: any): Promise<any>;
|
|
3
|
+
export function downloadBudget(syncId: any, { password }?: {
|
|
4
|
+
password: any;
|
|
5
|
+
}): Promise<any>;
|
|
6
|
+
export function batchBudgetUpdates(func: any): Promise<void>;
|
|
7
|
+
export function runQuery(query: any): any;
|
|
8
|
+
export function getBudgetMonths(): any;
|
|
9
|
+
export function getBudgetMonth(month: any): any;
|
|
10
|
+
export function setBudgetAmount(month: any, categoryId: any, value: any): any;
|
|
11
|
+
export function setBudgetCarryover(month: any, categoryId: any, flag: any): any;
|
|
12
|
+
export function addTransactions(accountId: any, transactions: any): any;
|
|
13
|
+
export function importTransactions(accountId: any, transactions: any): any;
|
|
14
|
+
export function getTransactions(accountId: any, startDate: any, endDate: any): any;
|
|
15
|
+
export function filterTransactions(accountId: any, text: any): any;
|
|
16
|
+
export function updateTransaction(id: any, fields: any): any;
|
|
17
|
+
export function deleteTransaction(id: any): any;
|
|
18
|
+
export function getAccounts(): any;
|
|
19
|
+
export function createAccount(account: any, initialBalance: any): any;
|
|
20
|
+
export function updateAccount(id: any, fields: any): any;
|
|
21
|
+
export function closeAccount(id: any, transferAccountId: any, transferCategoryId: any): any;
|
|
22
|
+
export function reopenAccount(id: any): any;
|
|
23
|
+
export function deleteAccount(id: any): any;
|
|
24
|
+
export function createCategoryGroup(group: any): any;
|
|
25
|
+
export function updateCategoryGroup(id: any, fields: any): any;
|
|
26
|
+
export function deleteCategoryGroup(id: any, transferCategoryId: any): any;
|
|
27
|
+
export function getCategories(): any;
|
|
28
|
+
export function createCategory(category: any): any;
|
|
29
|
+
export function updateCategory(id: any, fields: any): any;
|
|
30
|
+
export function deleteCategory(id: any, transferCategoryId: any): any;
|
|
31
|
+
export function getPayees(): any;
|
|
32
|
+
export function createPayee(payee: any): any;
|
|
33
|
+
export function updatePayee(id: any, fields: any): any;
|
|
34
|
+
export function deletePayee(id: any): any;
|
|
35
|
+
export { default as q } from "./app/query";
|
package/dist/methods.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.deletePayee = exports.updatePayee = exports.createPayee = exports.getPayees = exports.deleteCategory = exports.updateCategory = exports.createCategory = exports.getCategories = exports.deleteCategoryGroup = exports.updateCategoryGroup = exports.createCategoryGroup = exports.deleteAccount = exports.reopenAccount = exports.closeAccount = exports.updateAccount = exports.createAccount = exports.getAccounts = exports.deleteTransaction = exports.updateTransaction = exports.filterTransactions = exports.getTransactions = exports.importTransactions = exports.addTransactions = exports.setBudgetCarryover = exports.setBudgetAmount = exports.getBudgetMonth = exports.getBudgetMonths = exports.runQuery = exports.batchBudgetUpdates = exports.downloadBudget = exports.loadBudget = exports.runImport = exports.q = void 0;
|
|
30
|
+
const injected = __importStar(require("./injected"));
|
|
31
|
+
var query_1 = require("./app/query");
|
|
32
|
+
Object.defineProperty(exports, "q", { enumerable: true, get: function () { return __importDefault(query_1).default; } });
|
|
33
|
+
function send(name, args) {
|
|
34
|
+
return injected.send(name, args);
|
|
35
|
+
}
|
|
36
|
+
async function runImport(name, func) {
|
|
37
|
+
await send('api/start-import', { budgetName: name });
|
|
38
|
+
try {
|
|
39
|
+
await func();
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
await send('api/abort-import');
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
await send('api/finish-import');
|
|
46
|
+
}
|
|
47
|
+
exports.runImport = runImport;
|
|
48
|
+
async function loadBudget(budgetId) {
|
|
49
|
+
return send('api/load-budget', { id: budgetId });
|
|
50
|
+
}
|
|
51
|
+
exports.loadBudget = loadBudget;
|
|
52
|
+
async function downloadBudget(syncId, { password } = {}) {
|
|
53
|
+
return send('api/download-budget', { syncId, password });
|
|
54
|
+
}
|
|
55
|
+
exports.downloadBudget = downloadBudget;
|
|
56
|
+
async function batchBudgetUpdates(func) {
|
|
57
|
+
await send('api/batch-budget-start');
|
|
58
|
+
try {
|
|
59
|
+
await func();
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
await send('api/batch-budget-end');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.batchBudgetUpdates = batchBudgetUpdates;
|
|
66
|
+
function runQuery(query) {
|
|
67
|
+
return send('api/query', { query: query.serialize() });
|
|
68
|
+
}
|
|
69
|
+
exports.runQuery = runQuery;
|
|
70
|
+
function getBudgetMonths() {
|
|
71
|
+
return send('api/budget-months');
|
|
72
|
+
}
|
|
73
|
+
exports.getBudgetMonths = getBudgetMonths;
|
|
74
|
+
function getBudgetMonth(month) {
|
|
75
|
+
return send('api/budget-month', { month });
|
|
76
|
+
}
|
|
77
|
+
exports.getBudgetMonth = getBudgetMonth;
|
|
78
|
+
function setBudgetAmount(month, categoryId, value) {
|
|
79
|
+
return send('api/budget-set-amount', { month, categoryId, amount: value });
|
|
80
|
+
}
|
|
81
|
+
exports.setBudgetAmount = setBudgetAmount;
|
|
82
|
+
function setBudgetCarryover(month, categoryId, flag) {
|
|
83
|
+
return send('api/budget-set-carryover', { month, categoryId, flag });
|
|
84
|
+
}
|
|
85
|
+
exports.setBudgetCarryover = setBudgetCarryover;
|
|
86
|
+
function addTransactions(accountId, transactions) {
|
|
87
|
+
return send('api/transactions-add', { accountId, transactions });
|
|
88
|
+
}
|
|
89
|
+
exports.addTransactions = addTransactions;
|
|
90
|
+
function importTransactions(accountId, transactions) {
|
|
91
|
+
return send('api/transactions-import', { accountId, transactions });
|
|
92
|
+
}
|
|
93
|
+
exports.importTransactions = importTransactions;
|
|
94
|
+
function getTransactions(accountId, startDate, endDate) {
|
|
95
|
+
return send('api/transactions-get', { accountId, startDate, endDate });
|
|
96
|
+
}
|
|
97
|
+
exports.getTransactions = getTransactions;
|
|
98
|
+
function filterTransactions(accountId, text) {
|
|
99
|
+
return send('api/transactions-filter', { accountId, text });
|
|
100
|
+
}
|
|
101
|
+
exports.filterTransactions = filterTransactions;
|
|
102
|
+
function updateTransaction(id, fields) {
|
|
103
|
+
return send('api/transaction-update', { id, fields });
|
|
104
|
+
}
|
|
105
|
+
exports.updateTransaction = updateTransaction;
|
|
106
|
+
function deleteTransaction(id) {
|
|
107
|
+
return send('api/transaction-delete', { id });
|
|
108
|
+
}
|
|
109
|
+
exports.deleteTransaction = deleteTransaction;
|
|
110
|
+
function getAccounts() {
|
|
111
|
+
return send('api/accounts-get');
|
|
112
|
+
}
|
|
113
|
+
exports.getAccounts = getAccounts;
|
|
114
|
+
function createAccount(account, initialBalance) {
|
|
115
|
+
return send('api/account-create', { account, initialBalance });
|
|
116
|
+
}
|
|
117
|
+
exports.createAccount = createAccount;
|
|
118
|
+
function updateAccount(id, fields) {
|
|
119
|
+
return send('api/account-update', { id, fields });
|
|
120
|
+
}
|
|
121
|
+
exports.updateAccount = updateAccount;
|
|
122
|
+
function closeAccount(id, transferAccountId, transferCategoryId) {
|
|
123
|
+
return send('api/account-close', {
|
|
124
|
+
id,
|
|
125
|
+
transferAccountId,
|
|
126
|
+
transferCategoryId,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
exports.closeAccount = closeAccount;
|
|
130
|
+
function reopenAccount(id) {
|
|
131
|
+
return send('api/account-reopen', { id });
|
|
132
|
+
}
|
|
133
|
+
exports.reopenAccount = reopenAccount;
|
|
134
|
+
function deleteAccount(id) {
|
|
135
|
+
return send('api/account-delete', { id });
|
|
136
|
+
}
|
|
137
|
+
exports.deleteAccount = deleteAccount;
|
|
138
|
+
function createCategoryGroup(group) {
|
|
139
|
+
return send('api/category-group-create', { group });
|
|
140
|
+
}
|
|
141
|
+
exports.createCategoryGroup = createCategoryGroup;
|
|
142
|
+
function updateCategoryGroup(id, fields) {
|
|
143
|
+
return send('api/category-group-update', { id, fields });
|
|
144
|
+
}
|
|
145
|
+
exports.updateCategoryGroup = updateCategoryGroup;
|
|
146
|
+
function deleteCategoryGroup(id, transferCategoryId) {
|
|
147
|
+
return send('api/category-group-delete', { id, transferCategoryId });
|
|
148
|
+
}
|
|
149
|
+
exports.deleteCategoryGroup = deleteCategoryGroup;
|
|
150
|
+
function getCategories() {
|
|
151
|
+
return send('api/categories-get', { grouped: false });
|
|
152
|
+
}
|
|
153
|
+
exports.getCategories = getCategories;
|
|
154
|
+
function createCategory(category) {
|
|
155
|
+
return send('api/category-create', { category });
|
|
156
|
+
}
|
|
157
|
+
exports.createCategory = createCategory;
|
|
158
|
+
function updateCategory(id, fields) {
|
|
159
|
+
return send('api/category-update', { id, fields });
|
|
160
|
+
}
|
|
161
|
+
exports.updateCategory = updateCategory;
|
|
162
|
+
function deleteCategory(id, transferCategoryId) {
|
|
163
|
+
return send('api/category-delete', { id, transferCategoryId });
|
|
164
|
+
}
|
|
165
|
+
exports.deleteCategory = deleteCategory;
|
|
166
|
+
function getPayees() {
|
|
167
|
+
return send('api/payees-get');
|
|
168
|
+
}
|
|
169
|
+
exports.getPayees = getPayees;
|
|
170
|
+
function createPayee(payee) {
|
|
171
|
+
return send('api/payee-create', { payee });
|
|
172
|
+
}
|
|
173
|
+
exports.createPayee = createPayee;
|
|
174
|
+
function updatePayee(id, fields) {
|
|
175
|
+
return send('api/payee-update', { id, fields });
|
|
176
|
+
}
|
|
177
|
+
exports.updatePayee = updatePayee;
|
|
178
|
+
function deletePayee(id) {
|
|
179
|
+
return send('api/payee-delete', { id });
|
|
180
|
+
}
|
|
181
|
+
exports.deletePayee = deletePayee;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function runMigration(db: any, uuid: any): Promise<void>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
async function runMigration(db, uuid) {
|
|
4
|
+
function getValue(node) {
|
|
5
|
+
return node.expr != null ? node.expr : node.cachedValue;
|
|
6
|
+
}
|
|
7
|
+
db.execQuery(`
|
|
8
|
+
CREATE TABLE zero_budget_months
|
|
9
|
+
(id TEXT PRIMARY KEY,
|
|
10
|
+
buffered INTEGER DEFAULT 0);
|
|
11
|
+
|
|
12
|
+
CREATE TABLE zero_budgets
|
|
13
|
+
(id TEXT PRIMARY KEY,
|
|
14
|
+
month INTEGER,
|
|
15
|
+
category TEXT,
|
|
16
|
+
amount INTEGER DEFAULT 0,
|
|
17
|
+
carryover INTEGER DEFAULT 0);
|
|
18
|
+
|
|
19
|
+
CREATE TABLE reflect_budgets
|
|
20
|
+
(id TEXT PRIMARY KEY,
|
|
21
|
+
month INTEGER,
|
|
22
|
+
category TEXT,
|
|
23
|
+
amount INTEGER DEFAULT 0,
|
|
24
|
+
carryover INTEGER DEFAULT 0);
|
|
25
|
+
|
|
26
|
+
CREATE TABLE notes
|
|
27
|
+
(id TEXT PRIMARY KEY,
|
|
28
|
+
note TEXT);
|
|
29
|
+
|
|
30
|
+
CREATE TABLE kvcache (key TEXT PRIMARY KEY, value TEXT);
|
|
31
|
+
CREATE TABLE kvcache_key (id INTEGER PRIMARY KEY, key REAL);
|
|
32
|
+
`);
|
|
33
|
+
// Migrate budget amounts and carryover
|
|
34
|
+
let budget = db.runQuery(`SELECT * FROM spreadsheet_cells WHERE name LIKE 'budget%!budget-%'`, [], true);
|
|
35
|
+
db.transaction(() => {
|
|
36
|
+
budget.forEach(monthBudget => {
|
|
37
|
+
let match = monthBudget.name.match(/^(budget-report|budget)(\d+)!budget-(.+)$/);
|
|
38
|
+
if (match == null) {
|
|
39
|
+
console.log('Warning: invalid budget month name', monthBudget.name);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
let type = match[1];
|
|
43
|
+
let month = match[2].slice(0, 4) + '-' + match[2].slice(4);
|
|
44
|
+
let dbmonth = parseInt(match[2]);
|
|
45
|
+
let cat = match[3];
|
|
46
|
+
let amount = parseInt(getValue(monthBudget));
|
|
47
|
+
if (isNaN(amount)) {
|
|
48
|
+
amount = 0;
|
|
49
|
+
}
|
|
50
|
+
let sheetName = monthBudget.name.split('!')[0];
|
|
51
|
+
let carryover = db.runQuery('SELECT * FROM spreadsheet_cells WHERE name = ?', [`${sheetName}!carryover-${cat}`], true);
|
|
52
|
+
let table = type === 'budget-report' ? 'reflect_budgets' : 'zero_budgets';
|
|
53
|
+
db.runQuery(`INSERT INTO ${table} (id, month, category, amount, carryover) VALUES (?, ?, ?, ?, ?)`, [
|
|
54
|
+
`${month}-${cat}`,
|
|
55
|
+
dbmonth,
|
|
56
|
+
cat,
|
|
57
|
+
amount,
|
|
58
|
+
carryover.length > 0 && getValue(carryover[0]) === 'true' ? 1 : 0,
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
// Migrate buffers
|
|
63
|
+
let buffers = db.runQuery(`SELECT * FROM spreadsheet_cells WHERE name LIKE 'budget%!buffered'`, [], true);
|
|
64
|
+
db.transaction(() => {
|
|
65
|
+
buffers.forEach(buffer => {
|
|
66
|
+
let match = buffer.name.match(/^budget(\d+)!buffered$/);
|
|
67
|
+
if (match) {
|
|
68
|
+
let month = match[1].slice(0, 4) + '-' + match[1].slice(4);
|
|
69
|
+
let amount = parseInt(getValue(buffer));
|
|
70
|
+
if (isNaN(amount)) {
|
|
71
|
+
amount = 0;
|
|
72
|
+
}
|
|
73
|
+
db.runQuery(`INSERT INTO zero_budget_months (id, buffered) VALUES (?, ?)`, [month, amount]);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
// Migrate notes
|
|
78
|
+
let notes = db.runQuery(`SELECT * FROM spreadsheet_cells WHERE name LIKE 'notes!%'`, [], true);
|
|
79
|
+
let parseNote = str => {
|
|
80
|
+
try {
|
|
81
|
+
let value = JSON.parse(str);
|
|
82
|
+
return value && value !== '' ? value : null;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
db.transaction(() => {
|
|
89
|
+
notes.forEach(note => {
|
|
90
|
+
let parsed = parseNote(getValue(note));
|
|
91
|
+
if (parsed) {
|
|
92
|
+
let [, id] = note.name.split('!');
|
|
93
|
+
db.runQuery(`INSERT INTO notes (id, note) VALUES (?, ?)`, [id, parsed]);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
db.execQuery(`
|
|
98
|
+
DROP TABLE spreadsheet_cells;
|
|
99
|
+
ANALYZE;
|
|
100
|
+
VACUUM;
|
|
101
|
+
`);
|
|
102
|
+
}
|
|
103
|
+
exports.default = runMigration;
|
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const api = __importStar(require("./index"));
|
|
27
|
+
async function run() {
|
|
28
|
+
let app = await api.init({ config: { dataDir: '/tmp' } });
|
|
29
|
+
await app.send('create-budget', { testMode: true });
|
|
30
|
+
}
|
|
31
|
+
run();
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.integerToAmount = exports.amountToInteger = void 0;
|
|
4
|
+
function amountToInteger(n) {
|
|
5
|
+
return Math.round(n * 100);
|
|
6
|
+
}
|
|
7
|
+
exports.amountToInteger = amountToInteger;
|
|
8
|
+
function integerToAmount(n) {
|
|
9
|
+
return parseFloat((n / 100).toFixed(2));
|
|
10
|
+
}
|
|
11
|
+
exports.integerToAmount = integerToAmount;
|
package/package.json
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@actual-app/api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "An API for Actual",
|
|
6
|
-
"main": "index.js",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
8
|
-
"
|
|
9
|
-
"default-db.sqlite",
|
|
10
|
-
"index.js",
|
|
11
|
-
"injected.js",
|
|
12
|
-
"methods.js",
|
|
13
|
-
"migrations",
|
|
14
|
-
"utils.js"
|
|
9
|
+
"dist"
|
|
15
10
|
],
|
|
16
11
|
"scripts": {
|
|
17
12
|
"lint": "eslint .",
|
|
18
|
-
"build": "yarn workspace loot-core build:api"
|
|
13
|
+
"build:app": "yarn workspace loot-core build:api",
|
|
14
|
+
"build:node": "tsc --p tsconfig.dist.json",
|
|
15
|
+
"build:migrations": "cp migrations/*.sql dist/migrations",
|
|
16
|
+
"build:default-db": "cp default-db.sqlite dist/",
|
|
17
|
+
"build": "rm -rf dist && yarn run build:app && yarn run build:node && yarn run build:migrations && yarn run build:default-db"
|
|
19
18
|
},
|
|
20
19
|
"dependencies": {
|
|
21
20
|
"better-sqlite3": "^8.2.0",
|
|
22
21
|
"node-fetch": "^2.6.9",
|
|
23
22
|
"uuid": "3.3.2"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.0.2"
|
|
24
26
|
}
|
|
25
27
|
}
|