ownledger 1.2.0 → 2.0.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 +28 -1
- package/CHANGELOG.md +48 -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-DEBzshne.js +1 -0
- package/assets/static/Accounts-C1iNsQsy.js +1 -0
- package/assets/static/Attention-qo4v70P1.js +1 -0
- package/assets/static/ByCategory-33P2zSs-.js +1 -0
- package/assets/static/CardDetail-CvRo7JPt.js +1 -0
- package/assets/static/Cards-C3AdusmT.js +1 -0
- package/assets/static/Cards-DuqZFxkQ.js +1 -0
- package/assets/static/CardsValue-BM9WUQmy.js +1 -0
- package/assets/static/Cashback-DsWyjgRr.js +1 -0
- package/assets/static/CategoryIcon-E6EWIpbr.js +1 -0
- package/assets/static/CategoryPicker-BPeJNSuM.js +1 -0
- package/assets/static/ChartWidget-Bk1TAvJM.js +1 -0
- package/assets/static/Combobox-lRNTmjKR.js +1 -0
- package/assets/static/Deposits-CgEFypxb.js +1 -0
- package/assets/static/DrillLink-pa6s17Xu.js +1 -0
- package/assets/static/Field-OkPhoYM1.js +1 -0
- package/assets/static/HomeEditor-DdrzEPe2.js +1 -0
- package/assets/static/Import-DrhHmL65.js +2 -0
- package/assets/static/IncomeSpending-Cveqr3xt.js +1 -0
- package/assets/static/KV-CKGyL0p7.js +1 -0
- package/assets/static/Left-Bs_oKU19.js +1 -0
- package/assets/static/Money-DCMKf898.js +1 -0
- package/assets/static/NetWorth-Cjd13J56.js +1 -0
- package/assets/static/Pace-CBUDNxzH.js +1 -0
- package/assets/static/Panel-CXjnsEN0.js +1 -0
- package/assets/static/PinDialog-DoGuAyi4.js +1 -0
- package/assets/static/Plans-EWJdPCJ3.js +1 -0
- package/assets/static/Recent-BmJjA5dK.js +1 -0
- package/assets/static/Reports-DSrLn_wC.js +1 -0
- package/assets/static/Settings-DdiEp2Qi.js +1 -0
- package/assets/static/Transactions-Cy0kgcLE.js +1 -0
- package/assets/static/TxRow-IqjFXpya.js +1 -0
- package/assets/static/Unusual-D5-L9ZOy.js +1 -0
- package/assets/static/Upcoming-CCqPol8c.js +1 -0
- package/assets/static/WhichCard-Butdi7AN.js +1 -0
- package/assets/static/arrow-up-C8D_7x_H.js +1 -0
- package/assets/static/bits-BoWPOwTB.js +1 -0
- package/assets/static/button-Cj0k8AtB.js +1 -0
- package/assets/static/cards-AZlSJQ0z.js +1 -0
- package/assets/static/charts-Cj_hTR4h.js +65 -0
- package/assets/static/chevron-down-BLodeu9a.js +1 -0
- package/assets/static/chevron-right-BetctQ6k.js +1 -0
- package/assets/static/createLucideIcon-DUW9Fpzj.js +1 -0
- package/assets/static/dialog-BIbLA-XP.js +1 -0
- package/assets/static/dist-CbNfxqbd.js +1 -0
- package/assets/static/dist-CetESl7K.js +1 -0
- package/assets/static/dist-DYP_TYPy.js +1 -0
- package/assets/static/dist-DaSyQKU7.js +1 -0
- package/assets/static/drill-t1zr57xi.js +1 -0
- package/assets/static/es2015-BgAh-EkH.js +41 -0
- package/assets/static/fold-CGWYt9Iu.js +1 -0
- package/assets/static/index-CBsgYTMJ.css +1 -0
- package/assets/static/index-DYyIpxqK.js +14 -0
- package/assets/static/queries-C_4ufx4u.js +1 -0
- package/assets/static/react-dom-CI34djkT.js +1 -0
- package/assets/static/select-2EwEpMf_.js +1 -0
- package/assets/static/shared-CR-hvb-r.js +1 -0
- package/assets/static/triangle-exclamation-point-C6padEUM.js +1 -0
- package/assets/static/useMutation-BWtHiYPX.js +1 -0
- package/dist/cli/cards.d.ts +2 -0
- package/dist/cli/cards.js +86 -0
- package/dist/cli/import.js +12 -2
- package/dist/cli/index.js +3 -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 +19 -0
- package/dist/modules/api.js +16 -0
- package/dist/modules/cards/api.d.ts +3 -0
- package/dist/modules/cards/api.js +73 -0
- package/dist/modules/cards/engine.d.ts +42 -0
- package/dist/modules/cards/engine.js +102 -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/worker/api.d.ts +11 -1
- package/dist/worker/api.js +167 -13
- package/dist/worker/bestcard.d.ts +32 -9
- package/dist/worker/bestcard.js +91 -51
- package/dist/worker/mcp.js +209 -30
- package/dist/worker/openwallet.d.ts +1 -1
- package/dist/worker/openwallet.js +41 -11
- package/dist/worker/version.d.ts +1 -1
- package/dist/worker/version.js +1 -1
- package/package.json +26 -4
- package/presets/misa.mapping.yaml +7 -0
- package/assets/app.css +0 -61
- package/assets/app.js +0 -369
package/dist/engine/actions.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { parse as parseYaml
|
|
1
|
+
import { parse as parseYaml } from "yaml";
|
|
2
2
|
import { checkFiles } from "./check.js";
|
|
3
3
|
import { flattenCategories } from "./categories.js";
|
|
4
4
|
import { isDate } from "./dates.js";
|
|
5
5
|
import { LEDGER_FILE_RE, loadLedger, parseJsonl, PATHS } from "./load.js";
|
|
6
|
-
import { applyChange, describeChange } from "./write.js";
|
|
6
|
+
import { applyChange, describeChange, yamlText } from "./write.js";
|
|
7
7
|
export class ActionError extends Error {
|
|
8
8
|
}
|
|
9
9
|
function newId(prefix = "t_") {
|
|
@@ -128,6 +128,10 @@ export function voidTransaction(files, id, reason, meta) {
|
|
|
128
128
|
const next = { ...old, void: true, ...(reason ? { void_reason: reason } : {}) };
|
|
129
129
|
return plan(files, { replaceTransactions: [trailed(next, "void", meta)] }, withMeta(`Void: ${old.date} ${old.note ?? ""}`.trim(), meta));
|
|
130
130
|
}
|
|
131
|
+
/** The ledger of a set of files, for actions that read it before building a change. */
|
|
132
|
+
export function loadForAction(files) {
|
|
133
|
+
return loadLedger(files);
|
|
134
|
+
}
|
|
131
135
|
/* ------------------------------------------------------------------ accounts, plans, prices */
|
|
132
136
|
export function addAccount(files, a) {
|
|
133
137
|
return plan(files, { addAccounts: [a] }, `Add account: ${a.name} (${a.type})`);
|
|
@@ -181,7 +185,7 @@ export function addCategory(files, c) {
|
|
|
181
185
|
if (list.some((x) => x.id === c.id))
|
|
182
186
|
throw new ActionError(`category ${c.parent ? c.parent + "/" : ""}${c.id} exists`);
|
|
183
187
|
list.push({ id: c.id, name: c.name });
|
|
184
|
-
return plan(files, { putFiles: { [PATHS.categories]:
|
|
188
|
+
return plan(files, { putFiles: { [PATHS.categories]: yamlText(cats) } }, `Add category: ${c.parent ? c.parent + "/" : ""}${c.id}`);
|
|
185
189
|
}
|
|
186
190
|
/** Rename a category (name), or move/rename its path and remap every line that uses it (or its children). */
|
|
187
191
|
export function editCategory(files, path, set) {
|
|
@@ -219,9 +223,9 @@ export function editCategory(files, path, set) {
|
|
|
219
223
|
change.replaceTransactions = replace;
|
|
220
224
|
const budgets = parseYaml(files[PATHS.budgets] ?? "[]");
|
|
221
225
|
if (budgets?.some((b) => remap(b.category) !== b.category)) {
|
|
222
|
-
change.putFiles = { [PATHS.budgets]:
|
|
226
|
+
change.putFiles = { [PATHS.budgets]: yamlText(budgets.map((b) => ({ ...b, category: remap(b.category) }))) };
|
|
223
227
|
}
|
|
224
228
|
}
|
|
225
|
-
change.putFiles = { ...(change.putFiles ?? {}), [PATHS.categories]:
|
|
229
|
+
change.putFiles = { ...(change.putFiles ?? {}), [PATHS.categories]: yamlText(cats) };
|
|
226
230
|
return plan(files, change, set.new_path ? `Move category: ${path} → ${set.new_path}` : `Rename category: ${path}`);
|
|
227
231
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FileMap } from "./load.js";
|
|
2
|
+
import type { ISODate, Ledger } from "./types.js";
|
|
3
|
+
import { type AttentionItem } from "../modules/index.js";
|
|
4
|
+
export type { AttentionItem };
|
|
5
|
+
/**
|
|
6
|
+
* "Needs you": what's due (from the modules that are on), then housekeeping. Sorted: red, amber, info;
|
|
7
|
+
* within each, by date. Money items come before housekeeping at the same severity.
|
|
8
|
+
*/
|
|
9
|
+
export declare function attention(l: Ledger, asOf: ISODate, o?: {
|
|
10
|
+
files?: FileMap;
|
|
11
|
+
check?: {
|
|
12
|
+
errors: number;
|
|
13
|
+
warnings: number;
|
|
14
|
+
};
|
|
15
|
+
}): AttentionItem[];
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { holdingsAt } from "./balances.js";
|
|
2
|
+
import { isSystemCategory } from "./categories.js";
|
|
3
|
+
import { addMonths, monthStart } from "./dates.js";
|
|
4
|
+
import { UNCATEGORISED } from "./insights.js";
|
|
5
|
+
import { typeDef } from "./registry.js";
|
|
6
|
+
import { budgets } from "./schedules.js";
|
|
7
|
+
import { MODULES } from "../modules/index.js";
|
|
8
|
+
const RANK = { red: 0, amber: 1, info: 2 };
|
|
9
|
+
/**
|
|
10
|
+
* "Needs you": what's due (from the modules that are on), then housekeeping. Sorted: red, amber, info;
|
|
11
|
+
* within each, by date. Money items come before housekeeping at the same severity.
|
|
12
|
+
*/
|
|
13
|
+
export function attention(l, asOf, o = {}) {
|
|
14
|
+
const files = o.files ?? {};
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const m of MODULES)
|
|
17
|
+
if (m.attention && m.on(l, asOf, files))
|
|
18
|
+
out.push(...m.attention(l, asOf, files));
|
|
19
|
+
for (const b of budgets(l, asOf).filter((x) => x.over)) {
|
|
20
|
+
out.push({ kind: "over_budget", severity: "amber", date: asOf, title: `Over budget: ${b.category} (${b.spent} of ${b.amount})`, amount: b.spent - b.amount, params: { category: b.category, budget: b.amount, spent: b.spent }, link: `#/transactions?category=${encodeURIComponent(b.category)}` });
|
|
21
|
+
}
|
|
22
|
+
// housekeeping
|
|
23
|
+
const from = addMonths(monthStart(asOf), -1);
|
|
24
|
+
let uncat = 0;
|
|
25
|
+
for (const t of l.transactions) {
|
|
26
|
+
if (t.void || t.date < from)
|
|
27
|
+
continue;
|
|
28
|
+
if (t.date > asOf)
|
|
29
|
+
break;
|
|
30
|
+
if (t.lines.some((ln) => ln.category && !isSystemCategory(ln.category) && UNCATEGORISED.has(ln.category.split("/")[0])))
|
|
31
|
+
uncat++;
|
|
32
|
+
}
|
|
33
|
+
if (uncat)
|
|
34
|
+
out.push({ kind: "uncategorised", severity: "info", date: asOf, title: `${uncat} transaction(s) since ${from} have no real category (other)`, count: uncat, params: { from }, link: `#/transactions?category=other&from=${from}`, ask: true });
|
|
35
|
+
const hs = holdingsAt(l, asOf);
|
|
36
|
+
const unmatched = new Set(["import-unmatched"]);
|
|
37
|
+
for (const [p, text] of Object.entries(files)) {
|
|
38
|
+
if (!/^imports\/[^/]+\.mapping\.yaml$/.test(p))
|
|
39
|
+
continue;
|
|
40
|
+
const m = /^unmatched_account:\s*["']?([A-Za-z0-9._-]+)/m.exec(text);
|
|
41
|
+
if (m)
|
|
42
|
+
unmatched.add(m[1]);
|
|
43
|
+
}
|
|
44
|
+
for (const a of l.accounts) {
|
|
45
|
+
if (a.closed && a.closed <= asOf)
|
|
46
|
+
continue;
|
|
47
|
+
const v = hs.get(a.id)?.amount ?? 0;
|
|
48
|
+
if (unmatched.has(a.id)) {
|
|
49
|
+
if (v !== 0)
|
|
50
|
+
out.push({ kind: "unmatched", severity: "info", date: asOf, title: `Transfers without their other side: ${a.name} holds ${v} (should be 0)`, amount: v, account: a.id, name: a.name, link: `#/transactions?account=${encodeURIComponent(a.id)}`, ask: true });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const def = typeDef(a.type);
|
|
54
|
+
if (v < 0 && def && !def.liability && !def.holdings)
|
|
55
|
+
out.push({ kind: "negative", severity: "info", date: asOf, title: `${a.name} (${a.id}) is negative: ${v}`, amount: v, account: a.id, name: a.name, link: `#/transactions?account=${encodeURIComponent(a.id)}`, ask: true });
|
|
56
|
+
}
|
|
57
|
+
if (o.check?.errors)
|
|
58
|
+
out.push({ kind: "check_errors", severity: "red", date: asOf, title: `ownledger check: ${o.check.errors} error(s)`, count: o.check.errors, link: "#/settings", ask: true });
|
|
59
|
+
if (o.check?.warnings)
|
|
60
|
+
out.push({ kind: "check_warnings", severity: "info", date: asOf, title: `ownledger check: ${o.check.warnings} warning(s)`, count: o.check.warnings, link: "#/settings", ask: true });
|
|
61
|
+
const house = (k) => ["uncategorised", "unmatched", "negative", "check_warnings", "unpriced"].includes(k);
|
|
62
|
+
return out.sort((a, b) => RANK[a.severity] - RANK[b.severity] || Number(house(a.kind)) - Number(house(b.kind)) || (a.date < b.date ? -1 : a.date > b.date ? 1 : 0));
|
|
63
|
+
}
|
package/dist/engine/check.js
CHANGED
|
@@ -3,12 +3,19 @@ import { isDate } from "./dates.js";
|
|
|
3
3
|
import { ledgerPath, loadLedger, PATHS } from "./load.js";
|
|
4
4
|
import { typeDef } from "./registry.js";
|
|
5
5
|
import { FORMAT } from "./types.js";
|
|
6
|
+
import { checkDashboards } from "./dashboard.js";
|
|
7
|
+
import { todayIn } from "./dates.js";
|
|
8
|
+
import { MODULES } from "../modules/index.js";
|
|
6
9
|
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
7
10
|
const EVERY = new Set(["month", "quarter", "year"]);
|
|
8
11
|
/** Load + check. `ok` is false when there is any error. Warnings never fail. */
|
|
9
12
|
export function checkFiles(files) {
|
|
10
13
|
const { ledger, issues } = loadLedger(files);
|
|
11
|
-
const
|
|
14
|
+
const asOf = todayIn();
|
|
15
|
+
const all = [...issues, ...checkLedger(ledger), ...checkDashboards(files, ledger)];
|
|
16
|
+
for (const m of MODULES)
|
|
17
|
+
if (m.check && m.on(ledger, asOf, files))
|
|
18
|
+
all.push(...m.check(ledger, files));
|
|
12
19
|
const errors = all.filter((i) => i.level === "error");
|
|
13
20
|
const warnings = all.filter((i) => i.level === "warning");
|
|
14
21
|
return { ok: errors.length === 0, errors, warnings, ledger };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type SeriesQuery } from "./insights.js";
|
|
2
|
+
import type { Issue, Ledger } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A person's dashboard: data/dashboards/<login>.yaml in the data repo. Widgets on a 12-column grid,
|
|
5
|
+
* and personal preferences (the "My money" pool). One file per GitHub login; no file = the defaults.
|
|
6
|
+
*/
|
|
7
|
+
export declare const GRID_COLS = 12;
|
|
8
|
+
export declare const DASHBOARD_DIR = "data/dashboards/";
|
|
9
|
+
export declare const dashboardPath: (login: string) => string;
|
|
10
|
+
/** Built-in widget types and the module they need (none = core). */
|
|
11
|
+
export declare const WIDGET_TYPES: Record<string, {
|
|
12
|
+
module?: string;
|
|
13
|
+
options?: string[];
|
|
14
|
+
}>;
|
|
15
|
+
export declare const CHART_KINDS: readonly ["stat", "line", "bar", "hbar", "table"];
|
|
16
|
+
export interface Widget {
|
|
17
|
+
id: string;
|
|
18
|
+
type: string;
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
w: number;
|
|
22
|
+
h: number;
|
|
23
|
+
title?: string;
|
|
24
|
+
query?: SeriesQuery;
|
|
25
|
+
chart?: (typeof CHART_KINDS)[number];
|
|
26
|
+
/** Options of built-in widgets (period, account, count, months). */
|
|
27
|
+
period?: string;
|
|
28
|
+
account?: string;
|
|
29
|
+
count?: number;
|
|
30
|
+
months?: number;
|
|
31
|
+
/** Added by the AI through the connector (the dashboard marks it). */
|
|
32
|
+
by_ai?: boolean;
|
|
33
|
+
[k: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
export interface PoolPrefs {
|
|
36
|
+
/** Group everyday accounts (cash, bank, e-wallet) into one balance. Default on. */
|
|
37
|
+
on?: boolean;
|
|
38
|
+
/** Its name (default "Tiền của tôi" / "My money", translated by the dashboard). */
|
|
39
|
+
name?: string;
|
|
40
|
+
/** Liquid accounts kept out of the pool (all liquid accounts are in it by default, new ones too). */
|
|
41
|
+
exclude?: string[];
|
|
42
|
+
/** Where everyday spending goes when no account is named. */
|
|
43
|
+
default_account?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface Dashboard {
|
|
46
|
+
version: 1;
|
|
47
|
+
widgets?: Widget[];
|
|
48
|
+
prefs?: {
|
|
49
|
+
pool?: PoolPrefs;
|
|
50
|
+
[k: string]: unknown;
|
|
51
|
+
};
|
|
52
|
+
[k: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
/** The default Home: what fits the ledger (features), four widgets. */
|
|
55
|
+
export declare function defaultWidgets(f: {
|
|
56
|
+
historyMonths: number;
|
|
57
|
+
empty: boolean;
|
|
58
|
+
}): Widget[];
|
|
59
|
+
export declare function parseDashboard(text: string | undefined): Dashboard | null;
|
|
60
|
+
export declare function writeDashboard(d: Dashboard): string;
|
|
61
|
+
/** Issues in one dashboard file. Errors make PUT /api/dashboard refuse it; unknown categories/accounts are warnings. */
|
|
62
|
+
export declare function checkDashboard(file: string, d: unknown, l: Ledger): Issue[];
|
|
63
|
+
/** Every dashboard file in the repo, checked. */
|
|
64
|
+
export declare function checkDashboards(files: Record<string, string>, l: Ledger): Issue[];
|
|
65
|
+
export interface Pool {
|
|
66
|
+
on: boolean;
|
|
67
|
+
name: string | null;
|
|
68
|
+
accounts: string[];
|
|
69
|
+
default_account: string | null;
|
|
70
|
+
}
|
|
71
|
+
/** The pool for a person's prefs: a view over the accounts, never a change to them. */
|
|
72
|
+
export declare function poolOf(l: Ledger, prefs: PoolPrefs | undefined, asOf: string): Pool;
|
|
@@ -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;
|