@happyvertical/smrt-ledgers 0.51.24 → 0.51.25
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 +2 -1
- package/README.md +46 -0
- package/dist/chunks/Account-Dr4tA_Gn.js +128 -0
- package/dist/chunks/Account-Dr4tA_Gn.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +215 -129
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +1013 -1010
- package/dist/smrt-knowledge.json +2236 -2236
- package/package.json +6 -5
package/AGENTS.md
CHANGED
|
@@ -4,7 +4,7 @@ Double-entry accounting with chart of accounts, journal lifecycle, and balance e
|
|
|
4
4
|
|
|
5
5
|
## Models
|
|
6
6
|
|
|
7
|
-
- **Account**: 5 types (asset/liability/equity/revenue/expense). Hierarchical via `parentId`. Debit-normal (asset, expense) vs credit-normal (liability, equity, revenue). Methods: `getAncestors()`, `getFullPath()`, `toTreeNode()`, `getBalance(asOfDate?)`.
|
|
7
|
+
- **Account**: 5 types (asset/liability/equity/revenue/expense). Hierarchical via `parentId`. Debit-normal (asset, expense) vs credit-normal (liability, equity, revenue). Methods: `getAncestors()`, `getFullPath()`, `toTreeNode()`, `getBalance(asOfDate?)`. Stored in `ledger_accounts` (explicit `tableName`), never the derived `accounts`: smrt-messages declares an unrelated `Account` on that table (#3098). `src/migrations/ledger-accounts-table.ts` (`smrt db:migrate-ledger-accounts`) moves pre-#3098 rows; the README has the operator sequence.
|
|
8
8
|
- **Journal**: lifecycle `draft → posted → voided`. **Immutable after posting** (can only void, not edit). `sourceModule`/`sourceRef` for cross-package attribution. Auto-numbered (e.g., "JNL-0001"). `summarize()` is AI-powered via the smrt-prompts registry (see Prompt Registry below).
|
|
9
9
|
- **JournalEntry**: debit XOR credit (not both, validated on save). Multi-currency via `exchangeRate`. Non-negative amounts required.
|
|
10
10
|
|
|
@@ -36,3 +36,4 @@ PII-conscious variable selection: `tenantId`, `sourceRef` (may reference custome
|
|
|
36
36
|
- **Account types inherited by children**: child cannot differ from parent type
|
|
37
37
|
- **getBalance() is async**: requires JournalEntryCollection query (not stored on Account)
|
|
38
38
|
- **Optional tenancy** on all models
|
|
39
|
+
- **Same-named `Account`**: reference the ledger model by constructor (`@foreignKey(Account)`) or qualified name (`@happyvertical/smrt-ledgers:Account`), never the bare string. The PostgreSQL lanes are `pnpm test:postgres` here (ledgers alone) and in smrt-messages (both packages loaded)
|
package/README.md
CHANGED
|
@@ -103,6 +103,14 @@ Each JournalEntry must have either a debit or a credit (not both, not zero). Amo
|
|
|
103
103
|
| `JournalCollection` | `createWithEntries()`, `findByNumber()`, `findByDateRange()`, `findBySource()`, `findByStatus()`, `findDrafts()`, `findPosted()` |
|
|
104
104
|
| `JournalEntryCollection` | `findByJournal()`, `findByAccount()`, `getAccountBalance()`, `getTrialBalance()`, `getAccountLedger()`, `getTotalsForDateRange()` |
|
|
105
105
|
|
|
106
|
+
### Migration
|
|
107
|
+
|
|
108
|
+
| Export | Description |
|
|
109
|
+
|--------|------------|
|
|
110
|
+
| `planLedgerAccountsTableMove(db)` | Count the ledger rows a pre-#3098 `accounts` table still holds, without writing |
|
|
111
|
+
| `migrateLedgerAccountsTable(db, options?)` | Move them into `ledger_accounts` (see [Upgrading](#upgrading-from-051x-the-ledger_accounts-table-3098)) |
|
|
112
|
+
| `LedgerAccountsTableMoveError` | Thrown when the move refuses (uncertain rows, id clash, missing table, non-PostgreSQL) |
|
|
113
|
+
|
|
106
114
|
### Types
|
|
107
115
|
|
|
108
116
|
| Export | Description |
|
|
@@ -118,6 +126,44 @@ Each JournalEntry must have either a debit or a credit (not both, not zero). Amo
|
|
|
118
126
|
| `AccountTree` | Tree of account nodes (roots array) |
|
|
119
127
|
| `AccountTreeNode` | Single node in account tree (account + children) |
|
|
120
128
|
|
|
129
|
+
## Upgrading from 0.51.x: the `ledger_accounts` table (#3098)
|
|
130
|
+
|
|
131
|
+
`Account` is stored in `ledger_accounts`. Earlier releases derived the table
|
|
132
|
+
name `accounts`, which `@happyvertical/smrt-messages` also uses for its
|
|
133
|
+
unrelated messaging `Account`; an app with both packages got one union table
|
|
134
|
+
whose rows each package read as its own. An existing database moves its ledger
|
|
135
|
+
accounts once, in a PostgreSQL maintenance window:
|
|
136
|
+
|
|
137
|
+
1. `smrt db:migrate` — creates `ledger_accounts`. It reports, and does not
|
|
138
|
+
apply, the `journal_entries.account_id` foreign key while the old one still
|
|
139
|
+
points at `accounts`.
|
|
140
|
+
2. `smrt db:migrate-ledger-accounts --dry-run`, then without `--dry-run` —
|
|
141
|
+
copies every ledger row (ids, hierarchy and metadata unchanged) into
|
|
142
|
+
`ledger_accounts`, detaches the ledger foreign keys from `accounts`, and
|
|
143
|
+
deletes the moved rows, in one locked transaction. Messaging rows (those
|
|
144
|
+
with an STI discriminator) stay. Before writing anything it refuses a row
|
|
145
|
+
whose owner is uncertain, ids already present in `ledger_accounts`, and any
|
|
146
|
+
foreign key into `accounts` that no registered model declares (it would
|
|
147
|
+
otherwise dangle, or cascade); a rerun is a no-op. The same step is
|
|
148
|
+
`migrateLedgerAccountsTable(db)` / `planLedgerAccountsTableMove(db)` from
|
|
149
|
+
this package — call it with the application's models registered, as the
|
|
150
|
+
CLI does.
|
|
151
|
+
3. `smrt db:migrate` — adds the foreign keys against `ledger_accounts`.
|
|
152
|
+
|
|
153
|
+
Afterwards `accounts` is either empty (ledgers only — drop it when nothing else
|
|
154
|
+
uses it) or holds only messaging accounts plus the unused ledger columns
|
|
155
|
+
`number`, `type`, `parent_id`, `description`, `active` and `metadata`, which
|
|
156
|
+
can be dropped once verified. A database that never ran ledgers needs nothing.
|
|
157
|
+
|
|
158
|
+
The move supports PostgreSQL. On SQLite, a database whose `accounts` table
|
|
159
|
+
holds only ledger accounts is upgraded with
|
|
160
|
+
`ALTER TABLE accounts RENAME TO ledger_accounts` before step 1; a SQLite
|
|
161
|
+
database that also holds messaging accounts must be rebuilt.
|
|
162
|
+
|
|
163
|
+
Code that referenced the ledger model by the bare name `'Account'` should use
|
|
164
|
+
the constructor or the qualified name `@happyvertical/smrt-ledgers:Account`;
|
|
165
|
+
the exported `Account` and `AccountCollection` are unchanged.
|
|
166
|
+
|
|
121
167
|
## Dependencies
|
|
122
168
|
|
|
123
169
|
- `@happyvertical/smrt-core` -- ORM and code generation
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { SmrtHierarchical, smrt } from "@happyvertical/smrt-core";
|
|
2
|
+
import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy";
|
|
3
|
+
//#region src/models/Account.ts
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
7
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
8
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
var Account = class extends SmrtHierarchical {
|
|
13
|
+
tenantId = null;
|
|
14
|
+
/**
|
|
15
|
+
* Account number (e.g., "1000", "5030")
|
|
16
|
+
*/
|
|
17
|
+
number = "";
|
|
18
|
+
/**
|
|
19
|
+
* Account name (e.g., "Cash", "Coffee Expense")
|
|
20
|
+
*/
|
|
21
|
+
name = "";
|
|
22
|
+
/**
|
|
23
|
+
* Account description
|
|
24
|
+
*/
|
|
25
|
+
description = "";
|
|
26
|
+
/**
|
|
27
|
+
* Account type - one of the 5 core types
|
|
28
|
+
*/
|
|
29
|
+
type = "asset";
|
|
30
|
+
/**
|
|
31
|
+
* Whether the account is active
|
|
32
|
+
*/
|
|
33
|
+
active = true;
|
|
34
|
+
/**
|
|
35
|
+
* Extensible metadata
|
|
36
|
+
*/
|
|
37
|
+
metadata = {};
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
super(options);
|
|
40
|
+
if (options.number !== void 0) this.number = options.number;
|
|
41
|
+
if (options.name !== void 0) this.name = options.name;
|
|
42
|
+
if (options.description !== void 0) this.description = options.description;
|
|
43
|
+
if (options.type !== void 0) this.type = options.type;
|
|
44
|
+
if (options.parentId !== void 0) this.parentId = options.parentId;
|
|
45
|
+
if (options.active !== void 0) this.active = options.active;
|
|
46
|
+
if (options.metadata !== void 0) this.metadata = options.metadata;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if this is a top-level account (no parent)
|
|
50
|
+
*/
|
|
51
|
+
isTopLevel() {
|
|
52
|
+
return this.parentId === null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if this is a debit-normal account (Asset, Expense)
|
|
56
|
+
* Debit-normal accounts increase with debits
|
|
57
|
+
*/
|
|
58
|
+
isDebitNormal() {
|
|
59
|
+
return this.type === "asset" || this.type === "expense";
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if this is a credit-normal account (Liability, Equity, Revenue)
|
|
63
|
+
* Credit-normal accounts increase with credits
|
|
64
|
+
*/
|
|
65
|
+
isCreditNormal() {
|
|
66
|
+
return this.type === "liability" || this.type === "equity" || this.type === "revenue";
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get full account path (e.g., "Assets > Current > Cash")
|
|
70
|
+
*/
|
|
71
|
+
async getFullPath() {
|
|
72
|
+
return [...(await this.getAncestors()).map((a) => a.name), this.name].join(" > ");
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build tree node for this account and its children
|
|
76
|
+
*/
|
|
77
|
+
async toTreeNode() {
|
|
78
|
+
const children = await this.getChildren();
|
|
79
|
+
const childNodes = await Promise.all(children.map((c) => c.toTreeNode()));
|
|
80
|
+
return {
|
|
81
|
+
account: this,
|
|
82
|
+
children: childNodes
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get the current balance of this account
|
|
87
|
+
*/
|
|
88
|
+
async getBalance(asOfDate) {
|
|
89
|
+
if (!this.id) return 0;
|
|
90
|
+
const { JournalEntryCollection } = await import("../index.js").then((n) => n.t);
|
|
91
|
+
return await (await JournalEntryCollection.create(this.options)).getAccountBalance(this.id, asOfDate);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a sub-account under this account
|
|
95
|
+
*/
|
|
96
|
+
async createChild(options) {
|
|
97
|
+
if (!this.id) throw new Error("Account must be saved before creating children");
|
|
98
|
+
const { AccountCollection } = await import("../index.js").then((n) => n.n);
|
|
99
|
+
const account = await (await AccountCollection.create(this.options)).create({
|
|
100
|
+
...options,
|
|
101
|
+
parentId: this.id,
|
|
102
|
+
type: this.type
|
|
103
|
+
});
|
|
104
|
+
await account.save();
|
|
105
|
+
return account;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
__decorateClass([tenantId({ nullable: true })], Account.prototype, "tenantId", 2);
|
|
109
|
+
Account = __decorateClass([TenantScoped({ mode: "optional" }), smrt({
|
|
110
|
+
tableName: "ledger_accounts",
|
|
111
|
+
api: { include: [
|
|
112
|
+
"list",
|
|
113
|
+
"get",
|
|
114
|
+
"create",
|
|
115
|
+
"update",
|
|
116
|
+
"delete"
|
|
117
|
+
] },
|
|
118
|
+
mcp: { include: [
|
|
119
|
+
"list",
|
|
120
|
+
"get",
|
|
121
|
+
"create"
|
|
122
|
+
] },
|
|
123
|
+
cli: { skipApiCheck: true }
|
|
124
|
+
})], Account);
|
|
125
|
+
//#endregion
|
|
126
|
+
export { Account as t };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=Account-Dr4tA_Gn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account-Dr4tA_Gn.js","names":[],"sources":["../../src/models/Account.ts"],"sourcesContent":["/**\n * Account model - Chart of accounts entry\n *\n * Represents a single account in the chart of accounts.\n * The 5 core types: Asset, Liability, Equity, Revenue, Expense\n */\n\nimport { SmrtHierarchical, smrt } from '@happyvertical/smrt-core';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport type { AccountOptions, AccountTreeNode, AccountType } from '../types';\n\n@TenantScoped({ mode: 'optional' })\n@smrt({\n // Own table, never the derived `accounts`: smrt-messages declares an\n // unrelated `Account` on that table (#3098). Existing `accounts`-hosted\n // ledgers move with `smrt db:migrate-ledger-accounts`.\n tableName: 'ledger_accounts',\n api: { include: ['list', 'get', 'create', 'update', 'delete'] },\n mcp: { include: ['list', 'get', 'create'] },\n cli: { skipApiCheck: true },\n})\nexport class Account extends SmrtHierarchical {\n /**\n * Tenant ID for multi-tenancy support (nullable for global accounts)\n */\n @tenantId({ nullable: true })\n tenantId: string | null = null;\n\n /**\n * Account number (e.g., \"1000\", \"5030\")\n */\n number: string = '';\n\n /**\n * Account name (e.g., \"Cash\", \"Coffee Expense\")\n */\n name: string = '';\n\n /**\n * Account description\n */\n description: string = '';\n\n /**\n * Account type - one of the 5 core types\n */\n type: AccountType = 'asset';\n\n // parentId inherited from SmrtHierarchical (null = top-level)\n\n /**\n * Whether the account is active\n */\n active: boolean = true;\n\n /**\n * Extensible metadata\n */\n metadata: Record<string, unknown> = {};\n\n constructor(options: AccountOptions = {}) {\n super(options);\n if (options.number !== undefined) this.number = options.number;\n if (options.name !== undefined) this.name = options.name;\n if (options.description !== undefined)\n this.description = options.description;\n if (options.type !== undefined) this.type = options.type;\n if (options.parentId !== undefined) this.parentId = options.parentId;\n if (options.active !== undefined) this.active = options.active;\n if (options.metadata !== undefined) this.metadata = options.metadata;\n }\n\n /**\n * Check if this is a top-level account (no parent)\n */\n isTopLevel(): boolean {\n return this.parentId === null;\n }\n\n /**\n * Check if this is a debit-normal account (Asset, Expense)\n * Debit-normal accounts increase with debits\n */\n isDebitNormal(): boolean {\n return this.type === 'asset' || this.type === 'expense';\n }\n\n /**\n * Check if this is a credit-normal account (Liability, Equity, Revenue)\n * Credit-normal accounts increase with credits\n */\n isCreditNormal(): boolean {\n return (\n this.type === 'liability' ||\n this.type === 'equity' ||\n this.type === 'revenue'\n );\n }\n\n // Hierarchy traversal (getParent / getChildren / getAncestors /\n // getDescendants / getHierarchy / moveTo) provided by SmrtHierarchical.\n // Account-specific helpers (getFullPath / getBalance / createChild /\n // toTreeNode) remain below.\n\n /**\n * Get full account path (e.g., \"Assets > Current > Cash\")\n */\n async getFullPath(): Promise<string> {\n const ancestors = await this.getAncestors();\n const names = [...ancestors.map((a) => a.name), this.name];\n return names.join(' > ');\n }\n\n /**\n * Build tree node for this account and its children\n */\n async toTreeNode(): Promise<AccountTreeNode> {\n const children = await this.getChildren();\n const childNodes = await Promise.all(children.map((c) => c.toTreeNode()));\n return {\n account: this,\n children: childNodes,\n };\n }\n\n /**\n * Get the current balance of this account\n */\n async getBalance(asOfDate?: Date): Promise<number> {\n if (!this.id) return 0;\n const { JournalEntryCollection } = await import(\n '../collections/JournalEntries'\n );\n const collection = await JournalEntryCollection.create(this.options);\n return await collection.getAccountBalance(this.id, asOfDate);\n }\n\n /**\n * Create a sub-account under this account\n */\n async createChild(\n options: Omit<AccountOptions, 'parentId' | 'type'>,\n ): Promise<Account> {\n if (!this.id) {\n throw new Error('Account must be saved before creating children');\n }\n const { AccountCollection } = await import('../collections/Accounts');\n const collection = await AccountCollection.create(this.options);\n const account = await collection.create({\n ...options,\n parentId: this.id,\n type: this.type, // Inherit type from parent\n });\n await account.save();\n return account;\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBO,IAAM,UAAN,cAAsB,iBAAiB;CAK5C,WAA0B;;;;CAK1B,SAAiB;;;;CAKjB,OAAe;;;;CAKf,cAAsB;;;;CAKtB,OAAoB;;;;CAOpB,SAAkB;;;;CAKlB,WAAoC,CAAC;CAErC,YAAY,UAA0B,CAAC,GAAG;EACxC,MAAM,OAAO;EACb,IAAI,QAAQ,WAAW,KAAA,GAAW,KAAK,SAAS,QAAQ;EACxD,IAAI,QAAQ,SAAS,KAAA,GAAW,KAAK,OAAO,QAAQ;EACpD,IAAI,QAAQ,gBAAgB,KAAA,GAC1B,KAAK,cAAc,QAAQ;EAC7B,IAAI,QAAQ,SAAS,KAAA,GAAW,KAAK,OAAO,QAAQ;EACpD,IAAI,QAAQ,aAAa,KAAA,GAAW,KAAK,WAAW,QAAQ;EAC5D,IAAI,QAAQ,WAAW,KAAA,GAAW,KAAK,SAAS,QAAQ;EACxD,IAAI,QAAQ,aAAa,KAAA,GAAW,KAAK,WAAW,QAAQ;CAC9D;;;;CAKA,aAAsB;EACpB,OAAO,KAAK,aAAa;CAC3B;;;;;CAMA,gBAAyB;EACvB,OAAO,KAAK,SAAS,WAAW,KAAK,SAAS;CAChD;;;;;CAMA,iBAA0B;EACxB,OACE,KAAK,SAAS,eACd,KAAK,SAAS,YACd,KAAK,SAAS;CAElB;;;;CAUA,MAAM,cAA+B;EAGnC,OAAO,CADQ,IAAG,MADM,KAAK,aAAa,EAAA,CACd,KAAK,MAAM,EAAE,IAAI,GAAG,KAAK,IAC9C,CAAA,CAAM,KAAK,KAAK;CACzB;;;;CAKA,MAAM,aAAuC;EAC3C,MAAM,WAAW,MAAM,KAAK,YAAY;EACxC,MAAM,aAAa,MAAM,QAAQ,IAAI,SAAS,KAAK,MAAM,EAAE,WAAW,CAAC,CAAC;EACxE,OAAO;GACL,SAAS;GACT,UAAU;EACZ;CACF;;;;CAKA,MAAM,WAAW,UAAkC;EACjD,IAAI,CAAC,KAAK,IAAI,OAAO;EACrB,MAAM,EAAE,2BAA2B,MAAM,OACvC,cAAA,CAAA,MAAA,MAAA,EAAA,CAAA;EAGF,OAAO,OAAM,MADY,uBAAuB,OAAO,KAAK,OAAO,EAAA,CAC3C,kBAAkB,KAAK,IAAI,QAAQ;CAC7D;;;;CAKA,MAAM,YACJ,SACkB;EAClB,IAAI,CAAC,KAAK,IACR,MAAM,IAAI,MAAM,gDAAgD;EAElE,MAAM,EAAE,sBAAsB,MAAM,OAAO,cAAA,CAAA,MAAA,MAAA,EAAA,CAAA;EAE3C,MAAM,UAAU,OAAM,MADG,kBAAkB,OAAO,KAAK,OAAO,EAAA,CAC7B,OAAO;GACtC,GAAG;GACH,UAAU,KAAK;GACf,MAAM,KAAK;EACb,CAAC;EACD,MAAM,QAAQ,KAAK;EACnB,OAAO;CACT;AACF;AAlIE,gBAAA,CADC,SAAS,EAAE,UAAU,KAAK,CAAC,CAAA,GAJjB,QAKX,WAAA,YAAA,CAAA;AALW,UAAN,gBAAA,CAVN,aAAa,EAAE,MAAM,WAAW,CAAC,GACjC,KAAK;CAIJ,WAAW;CACX,KAAK,EAAE,SAAS;EAAC;EAAQ;EAAO;EAAU;EAAU;CAAQ,EAAE;CAC9D,KAAK,EAAE,SAAS;EAAC;EAAQ;EAAO;CAAQ,EAAE;CAC1C,KAAK,EAAE,cAAc,KAAK;AAC5B,CAAC,CAAA,GACY,OAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DatabaseInterface } from '@happyvertical/smrt-core/migrations';
|
|
1
2
|
import { PromptDefinition } from '@happyvertical/smrt-prompts';
|
|
2
3
|
import { ResolvedPromptAI } from '@happyvertical/smrt-prompts';
|
|
3
4
|
import { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
@@ -643,6 +644,56 @@ export declare interface JournalOptions extends SmrtClassOptions {
|
|
|
643
644
|
*/
|
|
644
645
|
export declare type JournalStatus = 'draft' | 'posted' | 'voided';
|
|
645
646
|
|
|
647
|
+
export declare const LEDGER_ACCOUNTS_TABLE = "ledger_accounts";
|
|
648
|
+
|
|
649
|
+
export declare const LEDGER_ACCOUNTS_TABLE_MOVE = "@happyvertical/smrt-ledgers:ledger-accounts-table:v1";
|
|
650
|
+
|
|
651
|
+
export declare class LedgerAccountsTableMoveError extends Error {
|
|
652
|
+
constructor(message: string);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export declare interface LedgerAccountsTableMoveOptions {
|
|
656
|
+
backfillName?: string;
|
|
657
|
+
packageName?: string;
|
|
658
|
+
/** PostgreSQL `lock_timeout`, milliseconds (default 30000). */
|
|
659
|
+
lockTimeout?: number;
|
|
660
|
+
/** PostgreSQL `statement_timeout`, milliseconds (default 60000). */
|
|
661
|
+
statementTimeout?: number;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export declare interface LedgerAccountsTableMovePlan {
|
|
665
|
+
/** Whether a legacy `accounts` table with ledger columns exists. */
|
|
666
|
+
legacyTable: boolean;
|
|
667
|
+
/** Ledger rows still in `accounts` that this migration would move. */
|
|
668
|
+
pending: number;
|
|
669
|
+
/** Messaging rows that stay in `accounts`. */
|
|
670
|
+
messagingRows: number;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
export declare interface LedgerAccountsTableMoveResult {
|
|
674
|
+
ran: boolean;
|
|
675
|
+
moved: number;
|
|
676
|
+
/** Rows (messaging accounts) left in `accounts`. */
|
|
677
|
+
remainingLegacyRows: number;
|
|
678
|
+
/** `table.column` foreign keys detached from `accounts`. */
|
|
679
|
+
detachedForeignKeys: string[];
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
export declare const LEGACY_ACCOUNTS_TABLE = "accounts";
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Move ledger accounts from `accounts` into `ledger_accounts` in one
|
|
686
|
+
* transaction under an exclusive lock. Operator-invoked and idempotent: a
|
|
687
|
+
* rerun, or a database that never had ledger rows in `accounts`, is a no-op.
|
|
688
|
+
*/
|
|
689
|
+
export declare function migrateLedgerAccountsTable(db: DatabaseInterface, options?: LedgerAccountsTableMoveOptions): Promise<LedgerAccountsTableMoveResult>;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Inspect the legacy table without changing anything. Read-only portable SQL,
|
|
693
|
+
* so it also reports what a SQLite database would need moved.
|
|
694
|
+
*/
|
|
695
|
+
export declare function planLedgerAccountsTableMove(db: DatabaseInterface): Promise<LedgerAccountsTableMovePlan>;
|
|
696
|
+
|
|
646
697
|
export declare function promptMessageOptions(ai: ResolvedPromptAI): {
|
|
647
698
|
maxTokens?: number | undefined;
|
|
648
699
|
temperature?: number | undefined;
|