ownledger 1.2.1 → 2.1.0
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/AGENTS.md +73 -1
- package/CHANGELOG.md +64 -0
- package/README.md +13 -0
- package/assets/apple-touch-icon.png +0 -0
- package/assets/icon-192.png +0 -0
- package/assets/icon-512.png +0 -0
- package/assets/icon-maskable-512.png +0 -0
- package/assets/index.html +15 -18
- package/assets/manifest.webmanifest +1 -1
- package/assets/static/Account-sw3qGLbB.js +1 -0
- package/assets/static/Accounts-DWyzX3qB.js +1 -0
- package/assets/static/Attention-DxV-4qdY.js +1 -0
- package/assets/static/ByCategory-B4P3ikmE.js +1 -0
- package/assets/static/CardDetail-CayBXBm-.js +1 -0
- package/assets/static/Cards-CVuOP8Bt.js +1 -0
- package/assets/static/Cards-XUBdWxyo.js +1 -0
- package/assets/static/CardsValue-EoW2jG_0.js +1 -0
- package/assets/static/Cashback-BibVYHf_.js +1 -0
- package/assets/static/CategoryIcon-HfjYhH1l.js +1 -0
- package/assets/static/CategoryPicker-BkmvzX2I.js +1 -0
- package/assets/static/ChartWidget-u09-whUU.js +1 -0
- package/assets/static/Combobox-xXeyjGgK.js +1 -0
- package/assets/static/Deposits-CLAda4dj.js +1 -0
- package/assets/static/DrillLink-Bvfam9FA.js +1 -0
- package/assets/static/Field-tKFmKDEF.js +1 -0
- package/assets/static/HomeEditor-4vxj5LMD.js +1 -0
- package/assets/static/Import-DwaaFpRJ.js +2 -0
- package/assets/static/IncomeSpending-RVDSxAK4.js +1 -0
- package/assets/static/KV-DMA1AlP-.js +1 -0
- package/assets/static/Left-C_4gTGSX.js +1 -0
- package/assets/static/Money-PfFNNDOw.js +1 -0
- package/assets/static/NetWorth-BSoseczC.js +1 -0
- package/assets/static/Pace-B8p-9174.js +1 -0
- package/assets/static/Panel-BnfWrw9R.js +1 -0
- package/assets/static/PinDialog-BqAU9Vh4.js +1 -0
- package/assets/static/Plans-2KuQH2_I.js +1 -0
- package/assets/static/Recent-Ccmb34bq.js +1 -0
- package/assets/static/Reports-Dd-dhclr.js +1 -0
- package/assets/static/Settings-BR8WBlen.js +1 -0
- package/assets/static/Transactions-BAuQ-6Eb.js +1 -0
- package/assets/static/TxRow-EKIIMQKa.js +1 -0
- package/assets/static/Unusual-CwFp8aA5.js +1 -0
- package/assets/static/Upcoming-B28roT9r.js +1 -0
- package/assets/static/WhichCard-B3kLc842.js +1 -0
- package/assets/static/arrow-up-D3gxUKLo.js +1 -0
- package/assets/static/bits-Dr2E0ObC.js +1 -0
- package/assets/static/button-rfwMVz0i.js +1 -0
- package/assets/static/cards-Bb5zjzRG.js +1 -0
- package/assets/static/charts-BqP7HKwP.js +65 -0
- package/assets/static/chevron-down-Co1w7ApZ.js +1 -0
- package/assets/static/chevron-right-Dqh3vs9Y.js +1 -0
- package/assets/static/createLucideIcon-flJrJK2p.js +1 -0
- package/assets/static/dialog-BuRqO4sc.js +1 -0
- package/assets/static/dist-B4_eGtNj.js +1 -0
- package/assets/static/dist-B7PR2b0C.js +1 -0
- package/assets/static/dist-BDn7ydjn.js +1 -0
- package/assets/static/dist-Dl-m8cc2.js +1 -0
- package/assets/static/drill-t1zr57xi.js +1 -0
- package/assets/static/es2015-DJh4h8NX.js +41 -0
- package/assets/static/fold-CGWYt9Iu.js +1 -0
- package/assets/static/index-eR1GkdC_.js +14 -0
- package/assets/static/index-iYMxgw-7.css +1 -0
- package/assets/static/queries-DZIMMe4i.js +1 -0
- package/assets/static/react-dom-wK_7mEjs.js +1 -0
- package/assets/static/select-eaSi9K-d.js +1 -0
- package/assets/static/shared-Box7on3B.js +1 -0
- package/assets/static/triangle-exclamation-point-CuL0XSJl.js +1 -0
- package/assets/static/useMutation-_Lw8xXWa.js +1 -0
- package/dist/cli/cards.d.ts +2 -0
- package/dist/cli/cards.js +86 -0
- package/dist/cli/check.js +7 -1
- package/dist/cli/dev.js +22 -2
- package/dist/cli/import.js +12 -2
- package/dist/cli/index.js +6 -0
- package/dist/cli/statements.d.ts +1 -0
- package/dist/cli/statements.js +231 -0
- package/dist/engine/actions.d.ts +5 -0
- package/dist/engine/actions.js +9 -5
- package/dist/engine/attention.d.ts +15 -0
- package/dist/engine/attention.js +63 -0
- package/dist/engine/check.js +8 -1
- package/dist/engine/dashboard.d.ts +72 -0
- package/dist/engine/dashboard.js +180 -0
- package/dist/engine/features.d.ts +20 -0
- package/dist/engine/features.js +37 -0
- package/dist/engine/index.d.ts +5 -0
- package/dist/engine/index.js +5 -0
- package/dist/engine/insights.d.ts +164 -0
- package/dist/engine/insights.js +534 -0
- package/dist/engine/load.js +6 -0
- package/dist/engine/registry.d.ts +2 -0
- package/dist/engine/registry.js +15 -33
- package/dist/engine/reports.d.ts +21 -2
- package/dist/engine/reports.js +51 -3
- package/dist/engine/schedules.d.ts +7 -84
- package/dist/engine/schedules.js +8 -207
- package/dist/engine/types.d.ts +2 -0
- package/dist/engine/write.d.ts +9 -0
- package/dist/engine/write.js +26 -5
- package/dist/import/mapping.js +6 -0
- package/dist/import/run.d.ts +7 -0
- package/dist/import/run.js +28 -1
- package/dist/modules/api.d.ts +22 -0
- package/dist/modules/api.js +16 -0
- package/dist/modules/cards/api.d.ts +3 -0
- package/dist/modules/cards/api.js +105 -0
- package/dist/modules/cards/engine.d.ts +42 -0
- package/dist/modules/cards/engine.js +102 -0
- package/dist/modules/cards/files.d.ts +11 -0
- package/dist/modules/cards/files.js +17 -0
- package/dist/modules/cards/index.d.ts +26 -0
- package/dist/modules/cards/index.js +304 -0
- package/dist/modules/cards/statements.d.ts +128 -0
- package/dist/modules/cards/statements.js +426 -0
- package/dist/modules/cards/terms.d.ts +105 -0
- package/dist/modules/cards/terms.js +194 -0
- package/dist/modules/cards/tracker.d.ts +36 -0
- package/dist/modules/cards/tracker.js +232 -0
- package/dist/modules/cards/types.d.ts +2 -0
- package/dist/modules/cards/types.js +16 -0
- package/dist/modules/deposits/engine.d.ts +14 -0
- package/dist/modules/deposits/engine.js +32 -0
- package/dist/modules/deposits/index.d.ts +2 -0
- package/dist/modules/deposits/index.js +24 -0
- package/dist/modules/deposits/types.d.ts +2 -0
- package/dist/modules/deposits/types.js +15 -0
- package/dist/modules/index.d.ts +5 -0
- package/dist/modules/index.js +10 -0
- package/dist/modules/insurance/index.d.ts +3 -0
- package/dist/modules/insurance/index.js +8 -0
- package/dist/modules/insurance/types.d.ts +2 -0
- package/dist/modules/insurance/types.js +3 -0
- package/dist/modules/investments/index.d.ts +2 -0
- package/dist/modules/investments/index.js +24 -0
- package/dist/modules/investments/types.d.ts +2 -0
- package/dist/modules/investments/types.js +7 -0
- package/dist/modules/loans/engine.d.ts +30 -0
- package/dist/modules/loans/engine.js +77 -0
- package/dist/modules/loans/index.d.ts +2 -0
- package/dist/modules/loans/index.js +27 -0
- package/dist/modules/loans/types.d.ts +2 -0
- package/dist/modules/loans/types.js +5 -0
- package/dist/modules/types.d.ts +39 -0
- package/dist/modules/types.js +1 -0
- package/dist/modules/util.d.ts +8 -0
- package/dist/modules/util.js +8 -0
- package/dist/node/scaffold.js +2 -2
- package/dist/node/statements.d.ts +64 -0
- package/dist/node/statements.js +218 -0
- package/dist/worker/api.d.ts +11 -1
- package/dist/worker/api.js +169 -13
- package/dist/worker/bestcard.d.ts +31 -9
- package/dist/worker/bestcard.js +78 -50
- package/dist/worker/github.d.ts +3 -1
- package/dist/worker/github.js +13 -2
- package/dist/worker/mcp.js +209 -30
- package/dist/worker/store.d.ts +2 -0
- package/dist/worker/store.js +7 -2
- package/dist/worker/tar.d.ts +2 -1
- package/dist/worker/tar.js +4 -1
- package/dist/worker/version.d.ts +1 -1
- package/dist/worker/version.js +1 -1
- package/package.json +28 -4
- package/presets/misa.mapping.yaml +7 -0
- package/assets/app.css +0 -61
- package/assets/app.js +0 -369
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { parse as parseYaml } from "yaml";
|
|
2
|
+
import { yamlText } from "./write.js";
|
|
3
|
+
import { flattenCategories } from "./categories.js";
|
|
4
|
+
import { typeDef } from "./registry.js";
|
|
5
|
+
import { PERIOD_PRESETS } from "./insights.js";
|
|
6
|
+
/**
|
|
7
|
+
* A person's dashboard: data/dashboards/<login>.yaml in the data repo. Widgets on a 12-column grid,
|
|
8
|
+
* and personal preferences (the "My money" pool). One file per GitHub login; no file = the defaults.
|
|
9
|
+
*/
|
|
10
|
+
export const GRID_COLS = 12;
|
|
11
|
+
export const DASHBOARD_DIR = "data/dashboards/";
|
|
12
|
+
export const dashboardPath = (login) => `${DASHBOARD_DIR}${login.toLowerCase().replace(/[^a-z0-9-]/g, "-")}.yaml`;
|
|
13
|
+
/** Built-in widget types and the module they need (none = core). */
|
|
14
|
+
export const WIDGET_TYPES = {
|
|
15
|
+
pace: {},
|
|
16
|
+
left: {},
|
|
17
|
+
attention: {},
|
|
18
|
+
unusual: {},
|
|
19
|
+
net_worth: {},
|
|
20
|
+
by_category: { options: ["period"] },
|
|
21
|
+
income_spending: { options: ["months"] },
|
|
22
|
+
recent: { options: ["count"] },
|
|
23
|
+
account: { options: ["account"] },
|
|
24
|
+
upcoming: {},
|
|
25
|
+
chart: { options: ["query", "chart", "title"] },
|
|
26
|
+
cards: { module: "cards" },
|
|
27
|
+
cashback: { module: "cards" },
|
|
28
|
+
which_card: { module: "cards" },
|
|
29
|
+
cards_value: { module: "cards" },
|
|
30
|
+
deposits: { module: "deposits" },
|
|
31
|
+
};
|
|
32
|
+
export const CHART_KINDS = ["stat", "line", "bar", "hbar", "table"];
|
|
33
|
+
const METRICS = ["spending", "income", "net", "balance", "count"];
|
|
34
|
+
const BYS = ["day", "week", "month", "category", "top", "account", "who", "event", "tag"];
|
|
35
|
+
/** The default Home: what fits the ledger (features), four widgets. */
|
|
36
|
+
export function defaultWidgets(f) {
|
|
37
|
+
if (f.empty)
|
|
38
|
+
return [];
|
|
39
|
+
const w = [
|
|
40
|
+
{ id: "month", type: "pace", x: 0, y: 0, w: 6, h: 4 },
|
|
41
|
+
{ id: "needs", type: "attention", x: 6, y: 0, w: 6, h: 4 },
|
|
42
|
+
];
|
|
43
|
+
if (f.historyMonths >= 2)
|
|
44
|
+
w.push({ id: "different", type: "unusual", x: 0, y: 4, w: 6, h: 4 });
|
|
45
|
+
else
|
|
46
|
+
w.push({ id: "left", type: "left", x: 0, y: 4, w: 6, h: 4 });
|
|
47
|
+
w.push({ id: "worth", type: "net_worth", x: 6, y: 4, w: 6, h: 4 });
|
|
48
|
+
return w;
|
|
49
|
+
}
|
|
50
|
+
export function parseDashboard(text) {
|
|
51
|
+
if (text === undefined)
|
|
52
|
+
return null;
|
|
53
|
+
const v = parseYaml(text);
|
|
54
|
+
return v && typeof v === "object" ? v : null;
|
|
55
|
+
}
|
|
56
|
+
export function writeDashboard(d) {
|
|
57
|
+
return yamlText(d);
|
|
58
|
+
}
|
|
59
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
60
|
+
/** Issues in one dashboard file. Errors make PUT /api/dashboard refuse it; unknown categories/accounts are warnings. */
|
|
61
|
+
export function checkDashboard(file, d, l) {
|
|
62
|
+
const out = [];
|
|
63
|
+
const err = (where, message) => out.push({ level: "error", file, where, message });
|
|
64
|
+
const warn = (where, message) => out.push({ level: "warning", file, where, message });
|
|
65
|
+
if (!d || typeof d !== "object" || Array.isArray(d)) {
|
|
66
|
+
err(undefined, "must be a YAML map with version and widgets");
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
const dash = d;
|
|
70
|
+
if (dash.version !== 1)
|
|
71
|
+
err("version", "version must be 1");
|
|
72
|
+
const { map: cats } = flattenCategories(l.categories);
|
|
73
|
+
const accounts = new Map(l.accounts.map((a) => [a.id, a]));
|
|
74
|
+
if (dash.widgets !== undefined && !Array.isArray(dash.widgets))
|
|
75
|
+
err("widgets", "widgets must be a list");
|
|
76
|
+
const ids = new Set();
|
|
77
|
+
for (const [i, w] of (Array.isArray(dash.widgets) ? dash.widgets : []).entries()) {
|
|
78
|
+
const where = w && typeof w.id === "string" ? w.id : `#${i + 1}`;
|
|
79
|
+
if (!w || typeof w !== "object") {
|
|
80
|
+
err(where, "not a map");
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (typeof w.id !== "string" || !ID_RE.test(w.id))
|
|
84
|
+
err(where, "id must be letters, digits, . _ - (no spaces)");
|
|
85
|
+
else if (ids.has(w.id))
|
|
86
|
+
err(where, "duplicate widget id");
|
|
87
|
+
ids.add(w.id);
|
|
88
|
+
if (!Object.prototype.hasOwnProperty.call(WIDGET_TYPES, w.type))
|
|
89
|
+
err(where, `unknown widget type "${w.type}"`);
|
|
90
|
+
for (const k of ["x", "y", "w", "h"])
|
|
91
|
+
if (!Number.isInteger(w[k]) || w[k] < 0)
|
|
92
|
+
err(where, `${k} must be a whole number ≥ 0`);
|
|
93
|
+
if (Number.isInteger(w.w) && (w.w < 1 || w.w > GRID_COLS))
|
|
94
|
+
err(where, `w must be 1 to ${GRID_COLS}`);
|
|
95
|
+
if (Number.isInteger(w.h) && (w.h < 1 || w.h > 24))
|
|
96
|
+
err(where, "h must be 1 to 24");
|
|
97
|
+
if (Number.isInteger(w.x) && Number.isInteger(w.w) && w.x + w.w > GRID_COLS)
|
|
98
|
+
err(where, `x + w must be at most ${GRID_COLS}`);
|
|
99
|
+
if (w.title !== undefined && (typeof w.title !== "string" || w.title.length > 80))
|
|
100
|
+
err(where, "title: text up to 80 characters");
|
|
101
|
+
if (w.account !== undefined && w.account !== "pool" && !accounts.has(String(w.account)))
|
|
102
|
+
warn(where, `account "${w.account}" not found`);
|
|
103
|
+
if (w.type === "chart") {
|
|
104
|
+
const q = w.query;
|
|
105
|
+
if (!q || typeof q !== "object") {
|
|
106
|
+
err(where, "a chart widget needs a query");
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!METRICS.includes(q.metric))
|
|
110
|
+
err(where, `query.metric: one of ${METRICS.join(", ")}`);
|
|
111
|
+
if (q.by !== undefined && !BYS.includes(q.by))
|
|
112
|
+
err(where, `query.by: one of ${BYS.join(", ")}`);
|
|
113
|
+
if (q.metric === "balance" && q.by && !["day", "week", "month"].includes(q.by))
|
|
114
|
+
err(where, "query: balance goes by day, week or month");
|
|
115
|
+
if (q.period !== undefined && !PERIOD_PRESETS.includes(q.period) && !/^\d{4}(-\d{2})?$/.test(q.period))
|
|
116
|
+
err(where, `query.period: ${PERIOD_PRESETS.join(", ")}, yyyy-mm or yyyy`);
|
|
117
|
+
if (q.compare !== undefined && !["previous", "usual"].includes(q.compare))
|
|
118
|
+
err(where, "query.compare: previous or usual");
|
|
119
|
+
if (w.chart !== undefined && !CHART_KINDS.includes(w.chart))
|
|
120
|
+
err(where, `chart: one of ${CHART_KINDS.join(", ")}`);
|
|
121
|
+
if (q.category && !cats.has(q.category))
|
|
122
|
+
warn(where, `category "${q.category}" not found (the widget shows "category not found")`);
|
|
123
|
+
for (const a of q.account === undefined ? [] : Array.isArray(q.account) ? q.account : [q.account])
|
|
124
|
+
if (a !== "pool" && !accounts.has(a))
|
|
125
|
+
warn(where, `account "${a}" not found`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const pool = dash.prefs?.pool;
|
|
129
|
+
if (pool !== undefined) {
|
|
130
|
+
if (typeof pool !== "object" || pool === null)
|
|
131
|
+
err("prefs.pool", "must be a map");
|
|
132
|
+
else {
|
|
133
|
+
if (pool.on !== undefined && typeof pool.on !== "boolean")
|
|
134
|
+
err("prefs.pool.on", "true or false");
|
|
135
|
+
if (pool.name !== undefined && typeof pool.name !== "string")
|
|
136
|
+
err("prefs.pool.name", "text");
|
|
137
|
+
for (const a of pool.exclude ?? [])
|
|
138
|
+
if (!accounts.has(a))
|
|
139
|
+
warn("prefs.pool.exclude", `account "${a}" not found`);
|
|
140
|
+
if (pool.default_account !== undefined) {
|
|
141
|
+
const a = accounts.get(pool.default_account);
|
|
142
|
+
if (!a)
|
|
143
|
+
warn("prefs.pool.default_account", `account "${pool.default_account}" not found`);
|
|
144
|
+
else if (!typeDef(a.type)?.liquid)
|
|
145
|
+
warn("prefs.pool.default_account", `${a.id} is not an everyday account (cash, bank, e-wallet)`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
/** Every dashboard file in the repo, checked. */
|
|
152
|
+
export function checkDashboards(files, l) {
|
|
153
|
+
const out = [];
|
|
154
|
+
for (const [p, text] of Object.entries(files)) {
|
|
155
|
+
if (!p.startsWith(DASHBOARD_DIR))
|
|
156
|
+
continue;
|
|
157
|
+
if (!/^data\/dashboards\/[a-z0-9-]+\.yaml$/.test(p)) {
|
|
158
|
+
out.push({ level: "warning", file: p, message: "not a dashboard file name (data/dashboards/<login>.yaml); ignored" });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
let d;
|
|
162
|
+
try {
|
|
163
|
+
d = parseYaml(text);
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
out.push({ level: "error", file: p, message: `YAML parse error: ${e.message.split("\n")[0]}` });
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
out.push(...checkDashboard(p, d, l));
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
/** The pool for a person's prefs: a view over the accounts, never a change to them. */
|
|
174
|
+
export function poolOf(l, prefs, asOf) {
|
|
175
|
+
const on = prefs?.on ?? true;
|
|
176
|
+
const exclude = new Set(prefs?.exclude ?? []);
|
|
177
|
+
const accounts = l.accounts.filter((a) => typeDef(a.type)?.liquid && !exclude.has(a.id) && !(a.closed && a.closed <= asOf)).map((a) => a.id);
|
|
178
|
+
const def = prefs?.default_account && accounts.includes(prefs.default_account) ? prefs.default_account : (accounts.find((id) => l.accounts.find((a) => a.id === id)?.type === "cash") ?? accounts[0] ?? null);
|
|
179
|
+
return { on, name: prefs?.name ?? null, accounts: on ? accounts : [], default_account: on ? def : null };
|
|
180
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FileMap } from "./load.js";
|
|
2
|
+
import type { ISODate, Ledger } from "./types.js";
|
|
3
|
+
/** What the ledger has. The dashboard builds its nav, pages, sections and widget catalogue from this. */
|
|
4
|
+
export interface Features {
|
|
5
|
+
empty: boolean;
|
|
6
|
+
historyMonths: number;
|
|
7
|
+
accounts: number;
|
|
8
|
+
modules: string[];
|
|
9
|
+
cards: boolean;
|
|
10
|
+
deposits: boolean;
|
|
11
|
+
holdings: boolean;
|
|
12
|
+
liabilities: boolean;
|
|
13
|
+
plans: boolean;
|
|
14
|
+
imports: boolean;
|
|
15
|
+
who: boolean;
|
|
16
|
+
event: boolean;
|
|
17
|
+
tags: boolean;
|
|
18
|
+
budgets: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function features(l: Ledger, asOf: ISODate, files?: FileMap, pool?: string[]): Features;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { holdingsAt } from "./balances.js";
|
|
2
|
+
import { historyMonths } from "./insights.js";
|
|
3
|
+
import { typeDef } from "./registry.js";
|
|
4
|
+
import { MODULES } from "../modules/index.js";
|
|
5
|
+
export function features(l, asOf, files = {}, pool = []) {
|
|
6
|
+
const open = l.accounts.filter((a) => !(a.closed && a.closed <= asOf));
|
|
7
|
+
const hs = holdingsAt(l, asOf);
|
|
8
|
+
const modules = MODULES.filter((m) => m.on(l, asOf, files)).map((m) => m.name);
|
|
9
|
+
let who = false, event = false, tags = false, live = 0;
|
|
10
|
+
for (const t of l.transactions) {
|
|
11
|
+
if (t.void)
|
|
12
|
+
continue;
|
|
13
|
+
live++;
|
|
14
|
+
if (t.who)
|
|
15
|
+
who = true;
|
|
16
|
+
if (t.event)
|
|
17
|
+
event = true;
|
|
18
|
+
if (t.tags?.length)
|
|
19
|
+
tags = true;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
empty: live === 0,
|
|
23
|
+
historyMonths: historyMonths(l, asOf),
|
|
24
|
+
accounts: pool.length > 1 ? open.length - pool.length + 1 : open.length,
|
|
25
|
+
modules,
|
|
26
|
+
cards: modules.includes("cards"),
|
|
27
|
+
deposits: modules.includes("deposits"),
|
|
28
|
+
holdings: open.some((a) => typeDef(a.type)?.holdings || (a.asset !== undefined && a.asset !== l.meta.base)),
|
|
29
|
+
liabilities: open.some((a) => typeDef(a.type)?.liability && a.type !== "credit_card") || open.some((a) => (hs.get(a.id)?.amount ?? 0) < 0 && a.type !== "credit_card"),
|
|
30
|
+
plans: l.plans.length > 0,
|
|
31
|
+
imports: Object.keys(files).some((p) => /^imports\/[^/]+\.mapping\.yaml$/.test(p)),
|
|
32
|
+
who,
|
|
33
|
+
event,
|
|
34
|
+
tags,
|
|
35
|
+
budgets: l.budgets.length > 0,
|
|
36
|
+
};
|
|
37
|
+
}
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -11,3 +11,8 @@ export * from "./schedules.js";
|
|
|
11
11
|
export * from "./defaults.js";
|
|
12
12
|
export * from "./write.js";
|
|
13
13
|
export * from "./actions.js";
|
|
14
|
+
export * from "./insights.js";
|
|
15
|
+
export * from "./features.js";
|
|
16
|
+
export * from "./attention.js";
|
|
17
|
+
export * from "./dashboard.js";
|
|
18
|
+
export { MODULES, moduleByName } from "../modules/index.js";
|
package/dist/engine/index.js
CHANGED
|
@@ -11,3 +11,8 @@ export * from "./schedules.js";
|
|
|
11
11
|
export * from "./defaults.js";
|
|
12
12
|
export * from "./write.js";
|
|
13
13
|
export * from "./actions.js";
|
|
14
|
+
export * from "./insights.js";
|
|
15
|
+
export * from "./features.js";
|
|
16
|
+
export * from "./attention.js";
|
|
17
|
+
export * from "./dashboard.js";
|
|
18
|
+
export { MODULES, moduleByName } from "../modules/index.js";
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { type Period } from "./reports.js";
|
|
2
|
+
import type { Category, ISODate, Ledger, Transaction } from "./types.js";
|
|
3
|
+
/** A category is "different" when it's at least this % off its usual… */
|
|
4
|
+
export declare const UNUSUAL_MIN_PCT = 30;
|
|
5
|
+
/** …and the difference is at least this share of your usual spending for the same days (keeps tiny categories out). */
|
|
6
|
+
export declare const UNUSUAL_MIN_SHARE = 0.03;
|
|
7
|
+
/** A transaction is unusually large when it's above this percentile of its category's lines in the last 12 months… */
|
|
8
|
+
export declare const LARGE_PERCENTILE = 0.99;
|
|
9
|
+
/** …and the category has at least this many lines to compare with. */
|
|
10
|
+
export declare const LARGE_MIN_SAMPLES = 20;
|
|
11
|
+
/** At most this many "What's different" cards. */
|
|
12
|
+
export declare const UNUSUAL_MAX = 5;
|
|
13
|
+
/** Expense categories that mean "not categorised yet" (the default `other`, or an explicit `uncategorized`). */
|
|
14
|
+
export declare const UNCATEGORISED: Set<string>;
|
|
15
|
+
export interface Flow {
|
|
16
|
+
income: number;
|
|
17
|
+
expense: number;
|
|
18
|
+
}
|
|
19
|
+
/** Income and spending of one transaction (transfers and system categories count 0). Optional category prefix filter. */
|
|
20
|
+
export declare function txFlow(t: Transaction, cats: Map<string, Category>, category?: string): Flow;
|
|
21
|
+
/** Income and spending per day from `from` to `to` (inclusive). */
|
|
22
|
+
export declare function flowsByDay(l: Ledger, from: ISODate, to: ISODate, category?: string): Map<ISODate, Flow>;
|
|
23
|
+
/** First date with income or spending (opening balances and transfers don't count), or null. */
|
|
24
|
+
export declare function firstActivity(l: Ledger): ISODate | null;
|
|
25
|
+
/** Whole months of history before the month of asOf (0 when the ledger starts this month). */
|
|
26
|
+
export declare function historyMonths(l: Ledger, asOf: ISODate): number;
|
|
27
|
+
export interface Pace {
|
|
28
|
+
asOf: ISODate;
|
|
29
|
+
month: string;
|
|
30
|
+
day: number;
|
|
31
|
+
daysInMonth: number;
|
|
32
|
+
spent: number;
|
|
33
|
+
income: number;
|
|
34
|
+
/** Cumulative spending by day of this month; null after asOf. */
|
|
35
|
+
daily: (number | null)[];
|
|
36
|
+
lastMonth: {
|
|
37
|
+
month: string;
|
|
38
|
+
toDate: number;
|
|
39
|
+
total: number;
|
|
40
|
+
daily: number[];
|
|
41
|
+
} | null;
|
|
42
|
+
/** Average of the last `months` whole months (only those with history), cumulative by day. */
|
|
43
|
+
usual: {
|
|
44
|
+
months: number;
|
|
45
|
+
toDate: number;
|
|
46
|
+
total: number;
|
|
47
|
+
incomeTotal: number;
|
|
48
|
+
daily: number[];
|
|
49
|
+
low: number[];
|
|
50
|
+
high: number[];
|
|
51
|
+
} | null;
|
|
52
|
+
/** Month-end estimate of spending. */
|
|
53
|
+
estimate: number;
|
|
54
|
+
/** Month-end estimate of income (at least what came in so far). */
|
|
55
|
+
incomeEstimate: number;
|
|
56
|
+
/** "usual" when estimated from your usual months, "run-rate" from this month's daily average. */
|
|
57
|
+
estimateFrom: "usual" | "run-rate";
|
|
58
|
+
}
|
|
59
|
+
/** This month's spending against last month and your usual month, at the same day. */
|
|
60
|
+
export declare function pace(l: Ledger, asOf: ISODate, months?: number): Pace;
|
|
61
|
+
export type UsualBy = "category" | "top" | "account" | "who" | "event" | "tag";
|
|
62
|
+
export interface UsualRow {
|
|
63
|
+
key: string;
|
|
64
|
+
name: string;
|
|
65
|
+
current: number;
|
|
66
|
+
usual: number;
|
|
67
|
+
change: number;
|
|
68
|
+
changePct: number | null;
|
|
69
|
+
}
|
|
70
|
+
export interface Usual {
|
|
71
|
+
period: Period;
|
|
72
|
+
kind: "income" | "expense";
|
|
73
|
+
months: number;
|
|
74
|
+
current: number;
|
|
75
|
+
usual: number;
|
|
76
|
+
rows: UsualRow[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The periods "your usual" is averaged over, for a period:
|
|
80
|
+
* - part of one month (1st … day d): days 1…d of each of the previous `months` months;
|
|
81
|
+
* - whole months (n of them): the previous `months` months, scaled to n months;
|
|
82
|
+
* - any other span of L days: the `months` months before it, scaled to L days.
|
|
83
|
+
* Returns the windows and the factor to multiply their sum by.
|
|
84
|
+
*/
|
|
85
|
+
export declare function usualWindows(p: Period, months: number): {
|
|
86
|
+
windows: Period[];
|
|
87
|
+
factor: number;
|
|
88
|
+
};
|
|
89
|
+
/** Each row this period against your usual for a period of the same length, sorted by the biggest change in money. */
|
|
90
|
+
export declare function usual(l: Ledger, period: Period, by?: UsualBy, o?: {
|
|
91
|
+
months?: number;
|
|
92
|
+
kind?: "income" | "expense";
|
|
93
|
+
}): Usual;
|
|
94
|
+
export type UnusualCard = {
|
|
95
|
+
kind: "category_up" | "category_down";
|
|
96
|
+
category: string;
|
|
97
|
+
name: string;
|
|
98
|
+
current: number;
|
|
99
|
+
usual: number;
|
|
100
|
+
changePct: number;
|
|
101
|
+
link: string;
|
|
102
|
+
} | {
|
|
103
|
+
kind: "new_category";
|
|
104
|
+
category: string;
|
|
105
|
+
name: string;
|
|
106
|
+
amount: number;
|
|
107
|
+
link: string;
|
|
108
|
+
} | {
|
|
109
|
+
kind: "new_who";
|
|
110
|
+
who: string;
|
|
111
|
+
amount: number;
|
|
112
|
+
count: number;
|
|
113
|
+
link: string;
|
|
114
|
+
} | {
|
|
115
|
+
kind: "large";
|
|
116
|
+
tx: string;
|
|
117
|
+
date: ISODate;
|
|
118
|
+
note: string;
|
|
119
|
+
category: string;
|
|
120
|
+
name: string;
|
|
121
|
+
amount: number;
|
|
122
|
+
typical: number;
|
|
123
|
+
link: string;
|
|
124
|
+
};
|
|
125
|
+
/** Up to five "What's different" cards for the month of asOf (needs 2 months of history). */
|
|
126
|
+
export declare function unusual(l: Ledger, asOf: ISODate): UnusualCard[];
|
|
127
|
+
export type Metric = "spending" | "income" | "net" | "balance" | "count";
|
|
128
|
+
export type SeriesBy = "day" | "week" | "month" | "category" | "top" | "account" | "who" | "event" | "tag";
|
|
129
|
+
export declare const PERIOD_PRESETS: readonly ["this-month", "last-month", "last-3-months", "last-6-months", "this-year", "last-year", "last-12-months", "all"];
|
|
130
|
+
export interface SeriesQuery {
|
|
131
|
+
metric: Metric;
|
|
132
|
+
category?: string;
|
|
133
|
+
account?: string | string[];
|
|
134
|
+
who?: string;
|
|
135
|
+
event?: string;
|
|
136
|
+
tag?: string;
|
|
137
|
+
text?: string;
|
|
138
|
+
period?: string;
|
|
139
|
+
from?: ISODate;
|
|
140
|
+
to?: ISODate;
|
|
141
|
+
by?: SeriesBy;
|
|
142
|
+
compare?: "previous" | "usual";
|
|
143
|
+
limit?: number;
|
|
144
|
+
}
|
|
145
|
+
export interface SeriesPoint {
|
|
146
|
+
key: string;
|
|
147
|
+
name: string;
|
|
148
|
+
value: number;
|
|
149
|
+
compare?: number;
|
|
150
|
+
}
|
|
151
|
+
export interface Series {
|
|
152
|
+
query: SeriesQuery;
|
|
153
|
+
period: Period;
|
|
154
|
+
by: SeriesBy;
|
|
155
|
+
total: number;
|
|
156
|
+
compareTotal?: number;
|
|
157
|
+
points: SeriesPoint[];
|
|
158
|
+
}
|
|
159
|
+
/** A preset or yyyy-mm / yyyy, resolved against asOf. */
|
|
160
|
+
export declare function resolvePeriod(spec: string | undefined, asOf: ISODate, firstDate?: ISODate | null): Period;
|
|
161
|
+
/** Monday of the week of d. */
|
|
162
|
+
export declare function weekStart(d: ISODate): ISODate;
|
|
163
|
+
/** The data for a chart widget. */
|
|
164
|
+
export declare function series(l: Ledger, q: SeriesQuery, asOf: ISODate): Series;
|