@wirecat/cli-core 0.606.0 → 0.607.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/CHANGELOG.md +186 -1
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/reads.js +5 -0
- package/dist/cli/app-mcp-command.d.ts +6 -2
- package/dist/cli/app-mcp-command.js +11 -2
- package/dist/cli/csv.d.ts +10 -0
- package/dist/cli/csv.js +22 -0
- package/dist/cli/early-refusal.d.ts +10 -0
- package/dist/cli/early-refusal.js +19 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/profile-token.d.ts +29 -0
- package/dist/cli/profile-token.js +65 -0
- package/dist/cli/program.js +4 -2
- package/dist/crm/cli/csv.d.ts +23 -0
- package/dist/crm/cli/csv.js +135 -0
- package/dist/crm/cli/index.d.ts +1 -1
- package/dist/crm/cli/index.js +33 -21
- package/dist/crm/cli/pipeline-view.d.ts +3 -0
- package/dist/crm/cli/pipeline-view.js +36 -0
- package/dist/crm/writes.d.ts +6 -4
- package/dist/crm/writes.js +17 -13
- package/dist/documents.d.ts +2 -0
- package/dist/documents.js +2 -0
- package/dist/domain/business.d.ts +79 -0
- package/dist/domain/business.js +42 -0
- package/dist/domain/finance.d.ts +2 -0
- package/dist/domain/finance.js +2 -2
- package/dist/domain/google-documents.d.ts +2 -0
- package/dist/domain/google-documents.js +3 -1
- package/dist/domain/money.d.ts +2 -0
- package/dist/domain/money.js +11 -3
- package/dist/domain/providers.d.ts +36 -1
- package/dist/domain/providers.js +69 -7
- package/dist/domain/record-fields.d.ts +42 -0
- package/dist/domain/record-fields.js +122 -0
- package/dist/domain/record-types.d.ts +489 -16
- package/dist/domain/record-types.js +374 -7
- package/dist/domain/records.d.ts +96 -5
- package/dist/domain/records.js +178 -32
- package/dist/domain/ref-summaries.js +5 -0
- package/dist/domain/references.d.ts +1 -1
- package/dist/domain/references.js +5 -0
- package/dist/domain/vcard.d.ts +25 -0
- package/dist/domain/vcard.js +267 -0
- package/dist/entities/deal.d.ts +14 -0
- package/dist/entities/deal.js +3 -0
- package/dist/entities/index.d.ts +12 -0
- package/dist/errors/reasons.js +61 -2
- package/dist/fetch/addresses.d.ts +5 -0
- package/dist/fetch/addresses.js +76 -0
- package/dist/fetch/page.d.ts +64 -0
- package/dist/fetch/page.js +256 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/meetings/calendar-text.d.ts +1 -1
- package/dist/meetings/calendar-text.js +4 -0
- package/dist/meetings/event-store.d.ts +2 -2
- package/dist/search/account-list.d.ts +4 -0
- package/dist/search/account-list.js +19 -8
- package/dist/search/query.js +2 -2
- package/dist/services/events-search.js +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/ingest.d.ts +56 -8
- package/dist/services/ingest.js +95 -61
- package/dist/services/messages-search.js +3 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.js +1 -0
- package/dist/services/proposals/kinds/contracts.d.ts +4 -0
- package/dist/services/proposals/kinds/contracts.js +9 -0
- package/dist/services/proposals/kinds/finance.d.ts +4 -0
- package/dist/services/proposals/kinds/finance.js +14 -35
- package/dist/services/proposals/kinds/orders.js +7 -30
- package/dist/services/proposals/kinds/shared.d.ts +27 -1
- package/dist/services/proposals/kinds/shared.js +34 -0
- package/dist/services/proposals/kinds/source-review.d.ts +4 -0
- package/dist/services/proposals/kinds/source-review.js +45 -0
- package/dist/services/proposals/kinds/subscriptions.d.ts +9 -0
- package/dist/services/proposals/kinds/subscriptions.js +24 -0
- package/dist/services/proposals/kinds/transactions.d.ts +4 -0
- package/dist/services/proposals/kinds/transactions.js +10 -0
- package/dist/services/proposals/registry.js +9 -0
- package/dist/services/search-all-meetings.js +2 -2
- package/dist/services/search-all.js +4 -3
- package/dist/services/search-kind.js +3 -3
- package/dist/store/decisions.js +5 -1
- package/dist/store/index.d.ts +14 -3
- package/dist/store/index.js +3 -0
- package/dist/store/people.js +1 -1
- package/dist/store/source-review.d.ts +64 -0
- package/dist/store/source-review.js +7 -0
- package/dist/store/sqlite/accounts.d.ts +1 -1
- package/dist/store/sqlite/accounts.js +24 -1
- package/dist/store/sqlite/added-sources.d.ts +82 -0
- package/dist/store/sqlite/added-sources.js +237 -0
- package/dist/store/sqlite/business-contracts.d.ts +90 -0
- package/dist/store/sqlite/business-contracts.js +182 -0
- package/dist/store/sqlite/calendar-events.js +7 -3
- package/dist/store/sqlite/calendar-forget.js +3 -0
- package/dist/store/sqlite/calendar.d.ts +21 -1
- package/dist/store/sqlite/calendar.js +27 -7
- package/dist/store/sqlite/chat-rekey.js +7 -0
- package/dist/store/sqlite/chats.d.ts +3 -1
- package/dist/store/sqlite/chats.js +15 -1
- package/dist/store/sqlite/crm-rows.d.ts +44 -0
- package/dist/store/sqlite/crm-rows.js +195 -0
- package/dist/store/sqlite/crm.d.ts +2 -11
- package/dist/store/sqlite/crm.js +11 -166
- package/dist/store/sqlite/deals.d.ts +4 -8
- package/dist/store/sqlite/deals.js +5 -3
- package/dist/store/sqlite/document-transfer/snapshot.js +2 -2
- package/dist/store/sqlite/emails.js +2 -0
- package/dist/store/sqlite/entity-types.d.ts +14 -9
- package/dist/store/sqlite/entity-types.js +4 -10
- package/dist/store/sqlite/evidence-signature.d.ts +114 -0
- package/dist/store/sqlite/evidence-signature.js +349 -0
- package/dist/store/sqlite/evidence-sources.d.ts +2 -1
- package/dist/store/sqlite/evidence-sources.js +7 -3
- package/dist/store/sqlite/facts.d.ts +7 -2
- package/dist/store/sqlite/facts.js +21 -5
- package/dist/store/sqlite/finance.d.ts +18 -105
- package/dist/store/sqlite/finance.js +100 -219
- package/dist/store/sqlite/knowledge.d.ts +8 -2
- package/dist/store/sqlite/knowledge.js +65 -71
- package/dist/store/sqlite/labelled.d.ts +3 -0
- package/dist/store/sqlite/labelled.js +11 -0
- package/dist/store/sqlite/link-kinds.d.ts +2 -0
- package/dist/store/sqlite/link-kinds.js +2 -0
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/memories.d.ts +23 -9
- package/dist/store/sqlite/memories.js +41 -13
- package/dist/store/sqlite/messages.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +103 -0
- package/dist/store/sqlite/money-lines.d.ts +48 -0
- package/dist/store/sqlite/money-lines.js +76 -0
- package/dist/store/sqlite/money-transactions.d.ts +132 -0
- package/dist/store/sqlite/money-transactions.js +295 -0
- package/dist/store/sqlite/notes.d.ts +11 -2
- package/dist/store/sqlite/notes.js +20 -25
- package/dist/store/sqlite/orders.d.ts +36 -6
- package/dist/store/sqlite/orders.js +126 -46
- package/dist/store/sqlite/payment-facts.js +1 -1
- package/dist/store/sqlite/private-people.js +2 -0
- package/dist/store/sqlite/products.d.ts +78 -0
- package/dist/store/sqlite/products.js +131 -0
- package/dist/store/sqlite/project-transfer/records.js +26 -1
- package/dist/store/sqlite/project-transfer/snapshot.js +5 -3
- package/dist/store/sqlite/proposed-actions.d.ts +1 -1
- package/dist/store/sqlite/proposed-actions.js +24 -7
- package/dist/store/sqlite/providers.d.ts +0 -4
- package/dist/store/sqlite/providers.js +20 -2
- package/dist/store/sqlite/record-matching.d.ts +80 -0
- package/dist/store/sqlite/record-matching.js +264 -0
- package/dist/store/sqlite/record-projection.d.ts +89 -0
- package/dist/store/sqlite/record-projection.js +50 -0
- package/dist/store/sqlite/record-projectors-direct.d.ts +17 -0
- package/dist/store/sqlite/record-projectors-direct.js +125 -0
- package/dist/store/sqlite/record-projectors-money.d.ts +26 -0
- package/dist/store/sqlite/record-projectors-money.js +214 -0
- package/dist/store/sqlite/record-projectors-phone.d.ts +28 -0
- package/dist/store/sqlite/record-projectors-phone.js +212 -0
- package/dist/store/sqlite/record-projectors.d.ts +3 -44
- package/dist/store/sqlite/record-projectors.js +7 -67
- package/dist/store/sqlite/record-relations.d.ts +24 -0
- package/dist/store/sqlite/record-relations.js +92 -0
- package/dist/store/sqlite/record-remap.d.ts +12 -0
- package/dist/store/sqlite/record-remap.js +92 -0
- package/dist/store/sqlite/record-run.d.ts +71 -0
- package/dist/store/sqlite/record-run.js +179 -0
- package/dist/store/sqlite/record-settling.d.ts +9 -0
- package/dist/store/sqlite/record-settling.js +74 -0
- package/dist/store/sqlite/record-stamps.d.ts +13 -0
- package/dist/store/sqlite/record-stamps.js +30 -0
- package/dist/store/sqlite/record-writes.d.ts +43 -0
- package/dist/store/sqlite/record-writes.js +307 -0
- package/dist/store/sqlite/records.d.ts +52 -42
- package/dist/store/sqlite/records.js +123 -353
- package/dist/store/sqlite/ref-summaries.d.ts +6 -5
- package/dist/store/sqlite/ref-summaries.js +60 -8
- package/dist/store/sqlite/refunds.d.ts +31 -0
- package/dist/store/sqlite/refunds.js +112 -0
- package/dist/store/sqlite/reviewed.d.ts +109 -0
- package/dist/store/sqlite/reviewed.js +173 -0
- package/dist/store/sqlite/schema.d.ts +2840 -83
- package/dist/store/sqlite/schema.js +256 -1
- package/dist/store/sqlite/source-review-marks.d.ts +54 -0
- package/dist/store/sqlite/source-review-marks.js +143 -0
- package/dist/store/sqlite/source-review.d.ts +54 -0
- package/dist/store/sqlite/source-review.js +221 -0
- package/dist/store/sqlite/stage-amounts.d.ts +14 -0
- package/dist/store/sqlite/stage-amounts.js +23 -0
- package/dist/store/sqlite/subscriptions.d.ts +135 -0
- package/dist/store/sqlite/subscriptions.js +294 -0
- package/dist/store/sqlite/text-input.d.ts +3 -0
- package/dist/store/sqlite/text-input.js +13 -0
- package/dist/store/sqlite/things.js +2 -9
- package/dist/store/sqlite/transaction.d.ts +15 -0
- package/dist/store/sqlite/transaction.js +57 -0
- package/dist/store/sqlite/wallets.d.ts +88 -0
- package/dist/store/sqlite/wallets.js +143 -0
- package/dist/store/store-errors.d.ts +1 -0
- package/dist/store/store-errors.js +45 -0
- package/dist/store/store.d.ts +16 -1
- package/dist/store/store.js +30 -6
- package/package.json +5 -2
- package/schemas/examples/records-business.jsonl +11 -0
- package/schemas/records-envelope.v1.schema.json +1160 -5
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { WALLET_KINDS, walletLine } from "../../domain/business.js";
|
|
2
|
+
import { currencyOf, formatDecimal, moneyOf, scaleOf, signedMinorUnits } from "../../domain/money.js";
|
|
3
|
+
import { fold } from "../normalize.js";
|
|
4
|
+
import { authorActor, authorOf } from "./memories.js";
|
|
5
|
+
import { requiredThing } from "./notes.js";
|
|
6
|
+
import { iso, isoDate, limitOf, oneOf, refuse, reviewedRowsOver, text, } from "./reviewed.js";
|
|
7
|
+
import { write } from "./transaction.js";
|
|
8
|
+
const WALLETS = "SELECT w.*, b.name AS author_name, b.kind AS author_kind FROM financial_accounts w " +
|
|
9
|
+
"LEFT JOIN bots b ON w.author_type = 'bot' AND b.id = w.author_id";
|
|
10
|
+
const SIGNED = "CASE t.direction WHEN 'in' THEN t.amount ELSE -t.amount END";
|
|
11
|
+
export const walletOperationsOver = (context) => {
|
|
12
|
+
const { database, now } = context;
|
|
13
|
+
const { partyOf, partyThing } = reviewedRowsOver(context);
|
|
14
|
+
const today = () => new Date(now()).toISOString().slice(0, 10);
|
|
15
|
+
const sumOf = (sql, ...params) => Number(database
|
|
16
|
+
.prepare(`SELECT coalesce(sum(${SIGNED}), 0) AS n FROM financial_transactions t WHERE ${sql}`)
|
|
17
|
+
.get(...params)?.n);
|
|
18
|
+
const walletOf = (row, until) => {
|
|
19
|
+
const currency = String(row.currency);
|
|
20
|
+
const scale = scaleOf(currency);
|
|
21
|
+
const opening = row.opening_balance == null ? null : Number(row.opening_balance);
|
|
22
|
+
const openingDate = row.opening_date == null ? null : String(row.opening_date);
|
|
23
|
+
const booked = sumOf("t.financial_account_id = ? AND t.review = 'confirmed' AND t.status = 'booked' AND t.deleted_at IS NULL " +
|
|
24
|
+
"AND (? IS NULL OR t.booked_date > ?) AND t.booked_date <= ?", Number(row.id), openingDate, openingDate, until);
|
|
25
|
+
const pending = sumOf("t.financial_account_id = ? AND t.deleted_at IS NULL AND t.review <> 'rejected' " +
|
|
26
|
+
"AND (t.status = 'pending' OR t.review = 'proposed') AND t.statement_date <= ?", Number(row.id), until);
|
|
27
|
+
const fields = {
|
|
28
|
+
name: String(row.name),
|
|
29
|
+
kind: row.kind,
|
|
30
|
+
currency,
|
|
31
|
+
numberHint: row.number_hint == null ? null : String(row.number_hint),
|
|
32
|
+
closed: row.closed_date != null,
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
id: String(row.id),
|
|
36
|
+
ref: `wallet:${row.id}`,
|
|
37
|
+
title: walletLine(fields),
|
|
38
|
+
name: fields.name,
|
|
39
|
+
kind: fields.kind,
|
|
40
|
+
currency,
|
|
41
|
+
institution: row.institution == null ? null : String(row.institution),
|
|
42
|
+
numberHint: fields.numberHint,
|
|
43
|
+
holder: partyOf(row.holder_type, row.holder_id),
|
|
44
|
+
openingBalance: opening === null ? null : formatDecimal(opening, scale),
|
|
45
|
+
openingDate,
|
|
46
|
+
closedDate: row.closed_date == null ? null : String(row.closed_date),
|
|
47
|
+
balance: moneyOf((opening ?? 0) + booked, currency),
|
|
48
|
+
until,
|
|
49
|
+
pending: moneyOf(pending, currency),
|
|
50
|
+
author: authorOf(row),
|
|
51
|
+
model: row.model == null ? null : String(row.model),
|
|
52
|
+
source: String(row.source),
|
|
53
|
+
createdAt: iso(row.created_at),
|
|
54
|
+
updatedAt: iso(row.updated_at),
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const rowOf = (reference) => {
|
|
58
|
+
const thing = requiredThing(database, reference.includes(":") ? reference : `wallet:${reference}`, "the wallet");
|
|
59
|
+
if (thing.type !== "wallet")
|
|
60
|
+
return refuse(`${reference} is not a wallet`, "wallet.ref");
|
|
61
|
+
return database.prepare(`${WALLETS} WHERE w.id = ?`).get(thing.id);
|
|
62
|
+
};
|
|
63
|
+
const hintOf = (value) => {
|
|
64
|
+
const hint = text(value, "a wallet's number", 64);
|
|
65
|
+
if (hint !== null && hint.replace(/\s/g, "").length > 4)
|
|
66
|
+
refuse("a wallet keeps only the last 4 characters of its number, never the whole of it", "wallet.number");
|
|
67
|
+
return hint === null ? null : hint.replace(/\s/g, "");
|
|
68
|
+
};
|
|
69
|
+
const openingOf = (by, balance, date, currency) => {
|
|
70
|
+
if (balance === undefined && date === undefined)
|
|
71
|
+
return undefined;
|
|
72
|
+
if (by !== "owner")
|
|
73
|
+
refuse("only the owner sets a wallet's opening balance", "finance.owner-only", "permission_error");
|
|
74
|
+
if ((balance == null) !== (date == null))
|
|
75
|
+
refuse("an opening balance comes with its day", "wallet.field");
|
|
76
|
+
if (balance == null || date == null)
|
|
77
|
+
return { units: null, date: null };
|
|
78
|
+
return {
|
|
79
|
+
units: signedMinorUnits(balance, currency, "an opening balance"),
|
|
80
|
+
date: isoDate(date, "the opening day"),
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
add: (input) => {
|
|
85
|
+
const kind = input.kind === undefined ? "bank" : oneOf(input.kind, WALLET_KINDS, "a wallet's kind");
|
|
86
|
+
const currency = currencyOf(input.currency);
|
|
87
|
+
const name = text(input.name, "a wallet's name", 200) ?? refuse("a wallet needs a name", "wallet.field");
|
|
88
|
+
const hint = hintOf(input.numberHint);
|
|
89
|
+
const institution = text(input.institution, "a wallet's bank", 200);
|
|
90
|
+
const opening = openingOf(input.by, input.openingBalance, input.openingDate, currency);
|
|
91
|
+
const id = write(database, () => {
|
|
92
|
+
const holder = partyThing(input.holder, "the holder");
|
|
93
|
+
const { actor, model } = authorActor(context, input.by);
|
|
94
|
+
const source = input.by === "owner" ? "owner" : (text(input.source, "a source", 80) ?? "agent");
|
|
95
|
+
const at = now();
|
|
96
|
+
return Number(database
|
|
97
|
+
.prepare("INSERT INTO financial_accounts (name, name_folded, kind, currency, institution, number_hint, holder_type, " +
|
|
98
|
+
"holder_id, opening_balance, opening_date, author_type, author_id, model, source, created_at, updated_at) " +
|
|
99
|
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id")
|
|
100
|
+
.get(name, fold(name), kind, currency, institution, hint, holder?.type ?? null, holder?.id ?? null, opening?.units ?? null, opening?.date ?? null, actor.type, actor.id, model, source, at, at)?.id);
|
|
101
|
+
});
|
|
102
|
+
return walletOf(rowOf(`wallet:${id}`), today());
|
|
103
|
+
},
|
|
104
|
+
get: (reference, options = {}) => walletOf(rowOf(reference), isoDate(options.until, "the last day counted") ?? today()),
|
|
105
|
+
list: (filter = {}) => {
|
|
106
|
+
const kind = filter.kind === undefined ? null : oneOf(filter.kind, WALLET_KINDS, "a kind");
|
|
107
|
+
const currency = filter.currency === undefined ? null : currencyOf(filter.currency);
|
|
108
|
+
const closed = filter.closed === undefined ? null : filter.closed ? 1 : 0;
|
|
109
|
+
return database
|
|
110
|
+
.prepare(`${WALLETS} WHERE w.deleted_at IS NULL AND (? IS NULL OR w.kind = ?) AND (? IS NULL OR w.currency = ?) ` +
|
|
111
|
+
"AND (? IS NULL OR (w.closed_date IS NOT NULL) = ?) ORDER BY w.name_folded, w.id LIMIT ?")
|
|
112
|
+
.all(kind, kind, currency, currency, closed, closed, limitOf(filter.limit))
|
|
113
|
+
.map((row) => walletOf(row, today()));
|
|
114
|
+
},
|
|
115
|
+
update: (reference, input) => {
|
|
116
|
+
const row = rowOf(reference);
|
|
117
|
+
if (row.deleted_at != null)
|
|
118
|
+
refuse(`wallet:${row.id} is deleted`, "wallet.ref");
|
|
119
|
+
authorActor(context, input.by);
|
|
120
|
+
const opening = openingOf(input.by, input.openingBalance, input.openingDate, String(row.currency));
|
|
121
|
+
const name = input.name === undefined ? String(row.name) : text(input.name, "a wallet's name", 200);
|
|
122
|
+
const institution = input.institution === undefined ? row.institution : text(input.institution, "a wallet's bank", 200);
|
|
123
|
+
const hint = input.numberHint === undefined ? row.number_hint : hintOf(input.numberHint);
|
|
124
|
+
const closed = input.closedDate === undefined ? row.closed_date : isoDate(input.closedDate, "the closing day");
|
|
125
|
+
write(database, () => {
|
|
126
|
+
database
|
|
127
|
+
.prepare("UPDATE financial_accounts SET name = ?, name_folded = ?, institution = ?, number_hint = ?, closed_date = ?, " +
|
|
128
|
+
"opening_balance = ?, opening_date = ?, updated_at = ? WHERE id = ?")
|
|
129
|
+
.run(name, fold(name), institution, hint, closed, opening === undefined ? row.opening_balance : opening.units, opening === undefined ? row.opening_date : opening.date, now(), Number(row.id));
|
|
130
|
+
});
|
|
131
|
+
return walletOf(rowOf(`wallet:${row.id}`), today());
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
export const walletsStoreOver = (context) => {
|
|
136
|
+
const operations = walletOperationsOver(context);
|
|
137
|
+
return {
|
|
138
|
+
add: async (input) => operations.add(input),
|
|
139
|
+
get: async (reference, options) => operations.get(reference, options),
|
|
140
|
+
list: async (filter) => operations.list(filter),
|
|
141
|
+
update: async (reference, input) => operations.update(reference, input),
|
|
142
|
+
};
|
|
143
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const storeErrors: <T>(area: T) => T;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { rehearsing } from "./sqlite/transaction.js";
|
|
3
|
+
/** Drizzle wraps whatever a query throws in its own `DrizzleQueryError`; a store refusal under it is the answer. */
|
|
4
|
+
const refusalOf = (error) => error instanceof Error && error.name === "DrizzleQueryError" && error.cause instanceof CliError ? error.cause : error;
|
|
5
|
+
/**
|
|
6
|
+
* A store area whose methods throw a store refusal (`store.dry-run`) as it was raised, not inside Drizzle's query
|
|
7
|
+
* error, so `reason`, exit codes and agents see it. Spies on the area still see every call. Only a dry run raises
|
|
8
|
+
* one, so outside it a call goes straight through, its promise untouched.
|
|
9
|
+
*/
|
|
10
|
+
const wrapped = new WeakMap();
|
|
11
|
+
export const storeErrors = (area) => {
|
|
12
|
+
if (typeof area !== "object" || area === null || area instanceof Promise)
|
|
13
|
+
return area;
|
|
14
|
+
const held = wrapped.get(area);
|
|
15
|
+
if (held)
|
|
16
|
+
return held;
|
|
17
|
+
const proxy = new Proxy(area, {
|
|
18
|
+
get: (target, name) => {
|
|
19
|
+
const value = Reflect.get(target, name, target);
|
|
20
|
+
// An area bound to an account is the area's member: its methods answer the same way.
|
|
21
|
+
if (typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype)
|
|
22
|
+
return storeErrors(value);
|
|
23
|
+
if (typeof value !== "function")
|
|
24
|
+
return value;
|
|
25
|
+
return (...args) => {
|
|
26
|
+
if (!rehearsing())
|
|
27
|
+
return Reflect.apply(value, target, args);
|
|
28
|
+
let answer;
|
|
29
|
+
try {
|
|
30
|
+
answer = Reflect.apply(value, target, args);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw refusalOf(error);
|
|
34
|
+
}
|
|
35
|
+
return answer instanceof Promise
|
|
36
|
+
? answer.catch((error) => {
|
|
37
|
+
throw refusalOf(error);
|
|
38
|
+
})
|
|
39
|
+
: answer;
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
wrapped.set(area, proxy);
|
|
44
|
+
return proxy;
|
|
45
|
+
};
|
package/dist/store/store.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { type SearchIndexStore } from "./search-index.js";
|
|
|
21
21
|
import { type SearchesStore } from "./searches.js";
|
|
22
22
|
import { type AgentActionsStore } from "./sqlite/agent-actions.js";
|
|
23
23
|
import { type BotUpdateStore } from "./sqlite/bot-updates.js";
|
|
24
|
+
import { type ContractsStore } from "./sqlite/business-contracts.js";
|
|
24
25
|
import { type CatalogStore } from "./sqlite/catalog.js";
|
|
25
26
|
import { type CrmCopies } from "./sqlite/crm.js";
|
|
26
27
|
import { type DealsStore } from "./sqlite/deals.js";
|
|
@@ -36,13 +37,17 @@ import { type MeetingVectors } from "./sqlite/meeting-vectors.js";
|
|
|
36
37
|
import { type StoredMeetings } from "./sqlite/meetings.js";
|
|
37
38
|
import { type MemoriesStore } from "./sqlite/memories.js";
|
|
38
39
|
import { type SourceMentionStore } from "./sqlite/mention-sources.js";
|
|
40
|
+
import { type TransactionsStore } from "./sqlite/money-transactions.js";
|
|
39
41
|
import { type NotesStore } from "./sqlite/notes.js";
|
|
40
42
|
import { type StoreOptions } from "./sqlite/open-store.js";
|
|
41
43
|
import { type OrdersStore } from "./sqlite/orders.js";
|
|
44
|
+
import { type ProductsStore } from "./sqlite/products.js";
|
|
42
45
|
import { type ProposedActionsStore } from "./sqlite/proposed-actions.js";
|
|
43
46
|
import { type RecordStore } from "./sqlite/records.js";
|
|
44
47
|
import { type RelationsStore } from "./sqlite/reported-relations.js";
|
|
48
|
+
import { type SubscriptionsStore } from "./sqlite/subscriptions.js";
|
|
45
49
|
import { type StoreTaskStore } from "./sqlite/tasks.js";
|
|
50
|
+
import { type WalletsStore } from "./sqlite/wallets.js";
|
|
46
51
|
import { type SyncStore } from "./sync.js";
|
|
47
52
|
import { type TagsStore } from "./tags.js";
|
|
48
53
|
import type { AccountKey } from "./types.js";
|
|
@@ -109,8 +114,18 @@ export interface MessageStore {
|
|
|
109
114
|
readonly finance: FinanceStore;
|
|
110
115
|
/** What the owner, his business or a client ordered and how far delivery got; an agent's wait for the owner. */
|
|
111
116
|
readonly orders: OrdersStore;
|
|
112
|
-
/** The owner's sales pipelines and the deals in them
|
|
117
|
+
/** The owner's sales pipelines and the deals in them, written directly by the owner and his agents. */
|
|
113
118
|
readonly deals: DealsStore;
|
|
119
|
+
/** What the owner or a supplier sells, with its price; written directly. */
|
|
120
|
+
readonly products: ProductsStore;
|
|
121
|
+
/** The contracts the owner works under; one with a value from an agent or an import waits for the owner. */
|
|
122
|
+
readonly contracts: ContractsStore;
|
|
123
|
+
/** Subscriptions the owner bills or pays, with a price history never overwritten. */
|
|
124
|
+
readonly subscriptions: SubscriptionsStore;
|
|
125
|
+
/** Bank accounts, cards and cash, with balances computed from their transactions. */
|
|
126
|
+
readonly wallets: WalletsStore;
|
|
127
|
+
/** What statements say moved on the wallets, split by category; an agent's or an import's wait for the owner. */
|
|
128
|
+
readonly transactions: TransactionsStore;
|
|
114
129
|
/** A CRM account's pipelines, deals, leads, contacts and companies, written as the CRM has them. */
|
|
115
130
|
readonly crm: CrmCopies;
|
|
116
131
|
/** Relationships a source account reports, written as a diff that never overrides the owner's. */
|
package/dist/store/store.js
CHANGED
|
@@ -13,9 +13,11 @@ import { rosterStoreOver } from "./roster.js";
|
|
|
13
13
|
import { searchIndexStoreOver } from "./search-index.js";
|
|
14
14
|
import { searchesStoreOver } from "./searches.js";
|
|
15
15
|
import * as accounts from "./sqlite/accounts.js";
|
|
16
|
+
import { addedSourcesOver } from "./sqlite/added-sources.js";
|
|
16
17
|
import { agentActionsStoreOver } from "./sqlite/agent-actions.js";
|
|
17
18
|
import * as attachmentTexts from "./sqlite/attachment-texts.js";
|
|
18
19
|
import { botUpdateStoreOver } from "./sqlite/bot-updates.js";
|
|
20
|
+
import { contractsStoreOver } from "./sqlite/business-contracts.js";
|
|
19
21
|
import { eventStoreOver } from "./sqlite/calendar.js";
|
|
20
22
|
import { catalogStoreOver } from "./sqlite/catalog.js";
|
|
21
23
|
import { contextEvidenceOver, contextIndexOver, contextRecordsOver } from "./sqlite/context-evidence.js";
|
|
@@ -37,17 +39,22 @@ import { meetingVectorsOver } from "./sqlite/meeting-vectors.js";
|
|
|
37
39
|
import { meetingStoreOver } from "./sqlite/meetings.js";
|
|
38
40
|
import { memoriesStoreOver } from "./sqlite/memories.js";
|
|
39
41
|
import { sourceMentionStoreOver } from "./sqlite/mention-sources.js";
|
|
42
|
+
import { transactionsStoreOver } from "./sqlite/money-transactions.js";
|
|
40
43
|
import { noteSearchOver } from "./sqlite/note-search.js";
|
|
41
44
|
import { notesStoreOver } from "./sqlite/notes.js";
|
|
42
45
|
import { openStoreContext } from "./sqlite/open-store.js";
|
|
43
46
|
import { ordersStoreOver } from "./sqlite/orders.js";
|
|
47
|
+
import { productsStoreOver } from "./sqlite/products.js";
|
|
44
48
|
import { projectAnnotationStoreOver } from "./sqlite/project-transfer/store.js";
|
|
45
49
|
import { proposedActionsStoreOver } from "./sqlite/proposed-actions.js";
|
|
46
50
|
import { recordStoreOver } from "./sqlite/records.js";
|
|
47
51
|
import { refSummariesOf } from "./sqlite/ref-summaries.js";
|
|
48
52
|
import { relationsStoreOver } from "./sqlite/reported-relations.js";
|
|
49
53
|
import * as stems from "./sqlite/stems.js";
|
|
54
|
+
import { subscriptionsStoreOver } from "./sqlite/subscriptions.js";
|
|
50
55
|
import { taskStoreOver } from "./sqlite/tasks.js";
|
|
56
|
+
import { walletsStoreOver } from "./sqlite/wallets.js";
|
|
57
|
+
import { storeErrors } from "./store-errors.js";
|
|
51
58
|
import { syncStoreOver } from "./sync.js";
|
|
52
59
|
import { tagsStoreOver } from "./tags.js";
|
|
53
60
|
import { accountVectorsOver, vectorsStoreOver } from "./vectors.js";
|
|
@@ -67,10 +74,7 @@ export const openStore = async (options = {}) => {
|
|
|
67
74
|
/** Built on first use, once, so a spy on an area sees every call. */
|
|
68
75
|
const once = (build) => {
|
|
69
76
|
let built;
|
|
70
|
-
return () =>
|
|
71
|
-
built ??= build();
|
|
72
|
-
return built;
|
|
73
|
-
};
|
|
77
|
+
return () => (built ??= storeErrors(build()));
|
|
74
78
|
};
|
|
75
79
|
const areaOf = (keyed, whole) => once(() => {
|
|
76
80
|
const part = keyed();
|
|
@@ -109,7 +113,7 @@ const storeOver = (context) => {
|
|
|
109
113
|
const tasks = once(() => taskStoreOver(context));
|
|
110
114
|
const sourceMentions = once(() => sourceMentionStoreOver(context));
|
|
111
115
|
const knowledge = once(() => knowledgeStoreOver(context));
|
|
112
|
-
const notes = once(() => ({ ...notesStoreOver(context), ...noteSearchOver(context) }));
|
|
116
|
+
const notes = once(() => ({ ...notesStoreOver(context), ...addedSourcesOver(context), ...noteSearchOver(context) }));
|
|
113
117
|
const catalog = once(() => catalogStoreOver(context));
|
|
114
118
|
const files = once(() => filesStoreOver(context));
|
|
115
119
|
const calendar = once(() => ({ ...eventStoreOver(context), ...eventSearchOver(context) }));
|
|
@@ -117,12 +121,17 @@ const storeOver = (context) => {
|
|
|
117
121
|
const evidenceFindings = once(() => evidenceFindingsStoreOver(context));
|
|
118
122
|
const mailFindings = once(() => mailFindingsStoreOver(context));
|
|
119
123
|
const refs = {
|
|
120
|
-
summaries: async (texts, options) => refSummariesOf(context.database, texts, options),
|
|
124
|
+
summaries: async (texts, options) => refSummariesOf(context.database, texts, { ...options, now: context.now() }),
|
|
121
125
|
};
|
|
122
126
|
const facts = once(() => factsStoreOver(context));
|
|
123
127
|
const finance = once(() => financeStoreOver(context));
|
|
124
128
|
const orders = once(() => ordersStoreOver(context));
|
|
125
129
|
const deals = once(() => dealsStoreOver(context));
|
|
130
|
+
const products = once(() => productsStoreOver(context));
|
|
131
|
+
const contracts = once(() => contractsStoreOver(context));
|
|
132
|
+
const subscriptions = once(() => subscriptionsStoreOver(context));
|
|
133
|
+
const wallets = once(() => walletsStoreOver(context));
|
|
134
|
+
const transactions = once(() => transactionsStoreOver(context));
|
|
126
135
|
const crm = once(() => crmCopiesOver(context, accountPeopleOver(context)));
|
|
127
136
|
const relations = once(() => relationsStoreOver(context));
|
|
128
137
|
const decisionRequests = once(() => decisionRequestStoreOver(context));
|
|
@@ -239,6 +248,21 @@ const storeOver = (context) => {
|
|
|
239
248
|
get deals() {
|
|
240
249
|
return deals();
|
|
241
250
|
},
|
|
251
|
+
get products() {
|
|
252
|
+
return products();
|
|
253
|
+
},
|
|
254
|
+
get contracts() {
|
|
255
|
+
return contracts();
|
|
256
|
+
},
|
|
257
|
+
get subscriptions() {
|
|
258
|
+
return subscriptions();
|
|
259
|
+
},
|
|
260
|
+
get wallets() {
|
|
261
|
+
return wallets();
|
|
262
|
+
},
|
|
263
|
+
get transactions() {
|
|
264
|
+
return transactions();
|
|
265
|
+
},
|
|
242
266
|
get crm() {
|
|
243
267
|
return crm();
|
|
244
268
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.607.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"wirecat": {
|
|
17
17
|
"store": {
|
|
18
|
-
"speaks":
|
|
18
|
+
"speaks": 57,
|
|
19
19
|
"minCompatible": 56
|
|
20
20
|
}
|
|
21
21
|
},
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
],
|
|
38
38
|
"exports": {
|
|
39
39
|
"./schemas/records-envelope.v1.schema.json": "./schemas/records-envelope.v1.schema.json",
|
|
40
|
+
"./schemas/examples/records-business.jsonl": "./schemas/examples/records-business.jsonl",
|
|
40
41
|
"./documents": {
|
|
41
42
|
"types": "./dist/documents.d.ts",
|
|
42
43
|
"default": "./dist/documents.js"
|
|
@@ -211,6 +212,7 @@
|
|
|
211
212
|
"prepublishOnly": "pnpm build",
|
|
212
213
|
"schema:check": "scripts/schema/check.sh",
|
|
213
214
|
"schema:render": "node scripts/schema/render.mjs",
|
|
215
|
+
"schema:envelope": "pnpm build && node scripts/records-envelope-schema.mjs && biome format --write schemas/records-envelope.v1.schema.json",
|
|
214
216
|
"parity:seed": "tsc --build && node --experimental-strip-types scripts/parity-seed.ts",
|
|
215
217
|
"parity:render": "node --experimental-strip-types scripts/parity-render.ts",
|
|
216
218
|
"parity:audit": "tsc --build && node --experimental-strip-types scripts/parity-audit.ts",
|
|
@@ -278,6 +280,7 @@
|
|
|
278
280
|
"@vitest/coverage-v8": "^5.0.5",
|
|
279
281
|
"@wirecat/cli-base": "0.82.0",
|
|
280
282
|
"@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
|
|
283
|
+
"ajv": "8.17.1",
|
|
281
284
|
"commander": "15.0.0",
|
|
282
285
|
"cspell": "10.4.0",
|
|
283
286
|
"drizzle-kit": "1.0.0-rc.5",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{"schema_version": 1, "options": {"lines": "products"}, "source": {"provider": "example-erp", "account": "demo", "batch_id": "2026-11-07"}}
|
|
2
|
+
{"key": "org", "type": "organization", "external_id": "C-1", "operation": "upsert", "revision": 1, "fields": {"name": "ООО Пример", "identifiers": [{"scheme": "tax-id:ru", "value": "7700000000"}]}}
|
|
3
|
+
{"key": "anna", "type": "person", "external_id": "P-1", "operation": "upsert", "fields": {"name": "Анна Образцова", "email": "anna@example.com"}, "relations": [{"role": "member-of", "type": "organization", "external_id": "C-1"}]}
|
|
4
|
+
{"key": "pipe", "type": "pipeline", "external_id": "sales", "operation": "upsert", "fields": {"kind": "deal", "name": "Sales", "stages": [{"external_id": "new", "name": "New", "position": 1, "outcome": "open"}, {"external_id": "won", "name": "Won", "position": 2, "outcome": "won"}]}}
|
|
5
|
+
{"key": "deal", "type": "deal", "external_id": "D-7", "operation": "upsert", "fields": {"title": "Rental fleet 2027", "pipeline": "sales", "stage": "new", "amount": "120000.00", "currency": "RUB"}, "relations": [{"role": "organization", "type": "organization", "external_id": "C-1"}, {"role": "person", "type": "person", "external_id": "P-1", "as": "decision-maker"}]}
|
|
6
|
+
{"key": "svc", "type": "product", "external_id": "SKU-RENT", "operation": "upsert", "fields": {"kind": "service", "name": "Bike rental, month", "unit": "month", "unit_price": "10000.00", "currency": "RUB"}}
|
|
7
|
+
{"key": "contract", "type": "contract", "external_id": "K-2026-14", "operation": "upsert", "fields": {"name": "Rental agreement", "kind": "service", "status": "active", "effective_date": "2026-11-01", "expiration_date": "2027-10-31", "auto_renew": true, "notice_days": 30, "value": "120000.00", "currency": "RUB"}, "relations": [{"role": "party", "type": "organization", "external_id": "C-1", "as": "customer"}, {"role": "deal", "type": "deal", "external_id": "D-7"}]}
|
|
8
|
+
{"key": "order", "type": "order", "external_id": "O-55", "operation": "upsert", "fields": {"number": "O-55", "direction": "sale", "purpose": "business", "order_date": "2026-11-02", "currency": "RUB", "lines": [{"product": "SKU-RENT", "quantity": "12", "unit_price": "10000.00"}]}, "relations": [{"role": "customer", "type": "organization", "external_id": "C-1"}, {"role": "contract", "type": "contract", "external_id": "K-2026-14"}]}
|
|
9
|
+
{"key": "inv", "type": "invoice", "external_id": "INV-901", "operation": "upsert", "fields": {"direction": "receivable", "number": "901", "currency": "RUB", "issue_date": "2026-11-03", "due_date": "2026-11-17", "lines": [{"product": "SKU-RENT", "description": "Rental, November", "quantity": "1", "unit_price": "10000.00", "amount": "10000.00"}]}, "relations": [{"role": "counterparty", "type": "organization", "external_id": "C-1"}, {"role": "contract", "type": "contract", "external_id": "K-2026-14"}]}
|
|
10
|
+
{"key": "pay", "type": "payment", "external_id": "PAY-3", "operation": "upsert", "fields": {"direction": "in", "amount": "10000.00", "currency": "RUB", "date": "2026-11-05"}, "relations": [{"role": "payer", "type": "organization", "external_id": "C-1"}, {"role": "settles", "type": "invoice", "external_id": "INV-901", "amount": "10000.00"}]}
|
|
11
|
+
{"key": "quote", "type": "custom:quote", "external_id": "Q-7", "operation": "upsert", "fields": {"valid_until": "2026-11-30", "options": [{"bikes": 12, "insurance": {"kind": "full"}}]}, "relations": [{"role": "quoted-for", "type": "deal", "external_id": "D-7"}]}
|