@wirecat/cli-core 0.605.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 +284 -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 +4 -1
- package/dist/cli/index.js +4 -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/cli/store-settings.js +38 -4
- 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 +36 -22
- package/dist/crm/cli/pipeline-view.d.ts +3 -0
- package/dist/crm/cli/pipeline-view.js +36 -0
- package/dist/crm/index.d.ts +2 -2
- package/dist/crm/index.js +1 -1
- package/dist/crm/source.d.ts +35 -5
- package/dist/crm/sync.d.ts +15 -7
- package/dist/crm/sync.js +169 -11
- 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/crm.d.ts +41 -2
- package/dist/domain/deals.d.ts +5 -2
- package/dist/domain/deals.js +5 -2
- 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/relations.d.ts +125 -0
- package/dist/domain/relations.js +107 -0
- package/dist/domain/vcard.d.ts +25 -0
- package/dist/domain/vcard.js +267 -0
- package/dist/entities/deal.d.ts +16 -2
- package/dist/entities/deal.js +5 -1
- package/dist/entities/index.d.ts +29 -13
- package/dist/entities/relationship.d.ts +8 -2
- package/dist/entities/relationship.js +8 -2
- package/dist/entities/task-results.d.ts +10 -10
- package/dist/errors/reasons.js +73 -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 +7 -4
- package/dist/index.js +6 -3
- package/dist/mail/cli/review.js +20 -6
- package/dist/mail/index.d.ts +1 -1
- package/dist/mail/marks.d.ts +10 -5
- package/dist/mail/marks.js +16 -8
- package/dist/mail/review.d.ts +5 -0
- 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/link-scorers/scan.js +2 -1
- package/dist/services/link-scorers/shared.js +2 -1
- 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/project-status/index.js +2 -1
- 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/services/stored-project-gathering.js +4 -3
- package/dist/store/decisions.js +5 -1
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +20 -4
- package/dist/store/index.js +4 -0
- package/dist/store/people.js +1 -1
- package/dist/store/project-transfer/request.d.ts +4 -1
- package/dist/store/project-transfer/schema.d.ts +9 -2
- package/dist/store/project-transfer/schema.js +4 -0
- package/dist/store/project-transfer/snapshot-model.d.ts +8 -2
- 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-settings.d.ts +28 -0
- package/dist/store/sqlite/crm-settings.js +80 -0
- package/dist/store/sqlite/crm.d.ts +42 -11
- package/dist/store/sqlite/crm.js +402 -196
- package/dist/store/sqlite/deals.d.ts +4 -8
- package/dist/store/sqlite/deals.js +8 -5
- 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/involvement-queue.js +4 -3
- package/dist/store/sqlite/knowledge.d.ts +14 -4
- package/dist/store/sqlite/knowledge.js +108 -102
- 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 +4 -3
- package/dist/store/sqlite/link-kinds.js +6 -2
- package/dist/store/sqlite/manifest.js +7 -0
- package/dist/store/sqlite/memories.d.ts +24 -10
- package/dist/store/sqlite/memories.js +73 -19
- package/dist/store/sqlite/messages.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +134 -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 +14 -4
- package/dist/store/sqlite/notes.js +43 -31
- package/dist/store/sqlite/orders.d.ts +36 -6
- package/dist/store/sqlite/orders.js +126 -46
- package/dist/store/sqlite/organizations.d.ts +8 -0
- package/dist/store/sqlite/organizations.js +14 -0
- package/dist/store/sqlite/payment-facts.js +1 -1
- package/dist/store/sqlite/person-preparation.d.ts +1 -1
- package/dist/store/sqlite/person-preparation.js +3 -2
- 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 +39 -3
- package/dist/store/sqlite/project-transfer/snapshot.d.ts +4 -1
- package/dist/store/sqlite/project-transfer/snapshot.js +11 -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/relation-list.d.ts +43 -0
- package/dist/store/sqlite/relation-list.js +133 -0
- package/dist/store/sqlite/relation-proposals.d.ts +28 -6
- package/dist/store/sqlite/relation-proposals.js +134 -10
- package/dist/store/sqlite/relation-reads.d.ts +8 -0
- package/dist/store/sqlite/relation-reads.js +7 -0
- package/dist/store/sqlite/relation-roles.d.ts +26 -0
- package/dist/store/sqlite/relation-roles.js +91 -0
- package/dist/store/sqlite/reported-relations.d.ts +63 -0
- package/dist/store/sqlite/reported-relations.js +132 -0
- package/dist/store/sqlite/reviewed.d.ts +109 -0
- package/dist/store/sqlite/reviewed.js +173 -0
- package/dist/store/sqlite/schema/link-revisions.d.ts +136 -0
- package/dist/store/sqlite/schema/link-revisions.js +11 -0
- package/dist/store/sqlite/schema/links.d.ts +360 -0
- package/dist/store/sqlite/schema/links.js +32 -0
- package/dist/store/sqlite/schema.d.ts +2769 -306
- package/dist/store/sqlite/schema.js +258 -25
- 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 +19 -1
- package/dist/store/store.js +35 -6
- package/package.json +6 -3
- package/schemas/examples/records-business.jsonl +11 -0
- package/schemas/records-envelope.v1.schema.json +1160 -5
|
@@ -1,324 +1,24 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { pointerOf, recordFingerprint, } from "../../domain/records.js";
|
|
5
|
-
import { accountPk, findAccountPk } from "./accounts.js";
|
|
6
|
-
import { financeOperationsOver } from "./finance.js";
|
|
2
|
+
import { IDENTITY_TYPES } from "../../domain/record-types.js";
|
|
3
|
+
import { findAccountPk } from "./accounts.js";
|
|
7
4
|
import { requiredThing } from "./notes.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return error.code === "not_found" ? "record.reference-not-found" : "record.entity";
|
|
17
|
-
};
|
|
18
|
-
/** A record's fingerprint without its settles relations: what an import may not change on a payment it proposed. */
|
|
19
|
-
const unsettled = (fields, relations) => recordFingerprint(fields, relations.filter((relation) => relation.role !== "settles"));
|
|
5
|
+
import { codeOf, refusal } from "./record-projection.js";
|
|
6
|
+
import { isDerived } from "./record-relations.js";
|
|
7
|
+
import { recordRemapOver } from "./record-remap.js";
|
|
8
|
+
import { recordRunOver } from "./record-run.js";
|
|
9
|
+
import { recordWritesOver } from "./record-writes.js";
|
|
10
|
+
import { read, rehearse, write } from "./transaction.js";
|
|
11
|
+
export { waitingPointer } from "./record-run.js";
|
|
12
|
+
const LIMIT = 1000;
|
|
20
13
|
const iso = (value) => new Date(Number(value)).toISOString();
|
|
14
|
+
const IDENTITY_SQL = IDENTITY_TYPES.map((type) => `'${type}'`).join(", ");
|
|
21
15
|
export const recordStoreOver = (context) => {
|
|
22
|
-
const { database
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
statement = database.prepare(text);
|
|
29
|
-
statements.set(text, statement);
|
|
30
|
-
}
|
|
31
|
-
return statement;
|
|
32
|
-
};
|
|
33
|
-
const entityRef = (type, id) => type == null ? null : (referenceOfThing(database, storedThing(type, id)) ?? `${String(type)}:${String(id)}`);
|
|
34
|
-
/** Roles a projection needs whose target has no entity yet, the entities of the rest, and what each invoice gets. */
|
|
35
|
-
const relatedOf = (recordId, type) => {
|
|
36
|
-
const roles = rolesOf(type);
|
|
37
|
-
const known = roles.map(([name]) => name);
|
|
38
|
-
const many = roles.flatMap(([name, role]) => (role.many ? [name] : []));
|
|
39
|
-
const rows = sql("SELECT rr.role, rr.amount, t.entity_type, t.entity_id FROM record_relations rr " +
|
|
40
|
-
"LEFT JOIN records t ON t.id = rr.target_id AND t.deleted_at IS NULL WHERE rr.record_id = ? ORDER BY rr.id").all(recordId);
|
|
41
|
-
const related = new Map();
|
|
42
|
-
const shares = [];
|
|
43
|
-
const missing = new Set();
|
|
44
|
-
for (const row of rows) {
|
|
45
|
-
const role = String(row.role);
|
|
46
|
-
if (!known.includes(role))
|
|
47
|
-
continue;
|
|
48
|
-
const ref = entityRef(row.entity_type, row.entity_id);
|
|
49
|
-
if (ref === null)
|
|
50
|
-
missing.add(role);
|
|
51
|
-
else
|
|
52
|
-
related.set(role, [...(related.get(role) ?? []), ref]);
|
|
53
|
-
if (ref !== null && role === "settles")
|
|
54
|
-
shares.push({ invoice: ref, amount: row.amount == null ? null : String(row.amount) });
|
|
55
|
-
}
|
|
56
|
-
for (const [role, refs] of related)
|
|
57
|
-
if (refs.length > 1 && !many.includes(role))
|
|
58
|
-
refusal(`a record has one ${role}`, "record.relation-ambiguous");
|
|
59
|
-
return { related, shares, missing: [...missing] };
|
|
60
|
-
};
|
|
61
|
-
/** Makes the proposal a waiting record stands for, once every reference it names has an entity. */
|
|
62
|
-
const project = (row, source) => {
|
|
63
|
-
const type = row.type;
|
|
64
|
-
const { related, shares, missing } = relatedOf(Number(row.id), type);
|
|
65
|
-
if (missing.length > 0)
|
|
66
|
-
return { missing };
|
|
67
|
-
const fields = JSON.parse(String(row.fields));
|
|
68
|
-
for (const name of FIELD_REFERENCE_ROLES)
|
|
69
|
-
stringField(fields, name);
|
|
70
|
-
const ref = RECORD_PROJECTORS[type](fields, { related, shares }, source, { finance, settle });
|
|
71
|
-
const entity = requiredThing(database, ref);
|
|
72
|
-
sql("UPDATE records SET entity_type = ?, entity_id = ?, projected_fingerprint = fingerprint WHERE id = ?").run(entity.type, entity.id, Number(row.id));
|
|
73
|
-
return { proposed: ref, missing: [] };
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* What other payments leave open on an invoice. Proposed ones count too: the owner confirms them later, so payments
|
|
77
|
-
* of one batch would otherwise each take the whole invoice.
|
|
78
|
-
*/
|
|
79
|
-
const freeOn = (invoice, payment) => {
|
|
80
|
-
const [target, own] = [requiredThing(database, invoice), requiredThing(database, payment)];
|
|
81
|
-
const row = sql("SELECT i.total - (SELECT coalesce(sum(a.amount), 0) FROM payment_allocations a JOIN payments p ON p.id = " +
|
|
82
|
-
"a.payment_id WHERE a.invoice_id = i.id AND a.payment_id <> ? AND p.deleted_at IS NULL " +
|
|
83
|
-
"AND p.review <> 'rejected') AS free FROM invoices i WHERE i.id = ?").get(own.id, target.id);
|
|
84
|
-
return Number(row?.free ?? 0);
|
|
85
|
-
};
|
|
86
|
-
/** A payment settles each invoice it names by the amount the source gives, then the rest as far as both allow. */
|
|
87
|
-
const settle = (made, shares) => {
|
|
88
|
-
const units = (amount) => minorUnits(amount, made.currency);
|
|
89
|
-
let left = units(made.unallocated);
|
|
90
|
-
const given = shares.filter((one) => one.amount !== null);
|
|
91
|
-
for (const { invoice, amount } of [...given, ...shares.filter((one) => one.amount === null)]) {
|
|
92
|
-
const share = amount === null ? Math.min(left, freeOn(invoice, made.ref)) : units(amount);
|
|
93
|
-
if (share <= 0)
|
|
94
|
-
continue;
|
|
95
|
-
finance.allocate({
|
|
96
|
-
payment: made.ref,
|
|
97
|
-
invoice,
|
|
98
|
-
amount: formatDecimal(share, scaleOf(made.currency)),
|
|
99
|
-
by: IMPORTER,
|
|
100
|
-
});
|
|
101
|
-
left -= share;
|
|
102
|
-
}
|
|
103
|
-
return made.ref;
|
|
104
|
-
};
|
|
105
|
-
/** A payment the import proposed and the owner has not decided yet takes its record's settles relations again. */
|
|
106
|
-
const resettle = (recordId, ref) => {
|
|
107
|
-
const payment = finance.payment(ref);
|
|
108
|
-
if (payment.review !== "proposed" || payment.author.type !== "bot" || payment.author.name !== IMPORTER.bot)
|
|
109
|
-
return false;
|
|
110
|
-
for (const { invoice } of payment.allocations)
|
|
111
|
-
finance.unallocate({ payment: ref, invoice, by: IMPORTER });
|
|
112
|
-
settle(finance.payment(ref), relatedOf(recordId, "payment").shares);
|
|
113
|
-
return true;
|
|
114
|
-
};
|
|
115
|
-
/** The settles amounts a payment record gives, refused at the first one that is not money or goes past the payment. */
|
|
116
|
-
const checkShares = (record) => {
|
|
117
|
-
const relations = record.relations ?? [];
|
|
118
|
-
if (record.type !== "payment" || !relations.some((relation) => relation.amount !== undefined))
|
|
119
|
-
return;
|
|
120
|
-
const fields = record.fields ?? {};
|
|
121
|
-
if (typeof fields.currency !== "string")
|
|
122
|
-
return;
|
|
123
|
-
const currency = fields.currency;
|
|
124
|
-
let left;
|
|
125
|
-
try {
|
|
126
|
-
left = minorUnits(fields.amount, currency);
|
|
127
|
-
}
|
|
128
|
-
catch {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
for (const [index, { amount }] of relations.entries()) {
|
|
132
|
-
if (amount === undefined)
|
|
133
|
-
continue;
|
|
134
|
-
const at = ["relations", index, "amount"];
|
|
135
|
-
let units = 0;
|
|
136
|
-
try {
|
|
137
|
-
units = minorUnits(amount, currency, "a settles amount");
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
if (!(error instanceof CliError))
|
|
141
|
-
throw error;
|
|
142
|
-
refusal(error.message, codeOf(error), at);
|
|
143
|
-
}
|
|
144
|
-
if (units <= 0)
|
|
145
|
-
refusal("a settles amount is more than 0", "money.amount", at);
|
|
146
|
-
left -= units;
|
|
147
|
-
if (left < 0)
|
|
148
|
-
refusal(`the settles amounts add up to more than the payment's ${String(fields.amount)} ${currency}`, "record.over-payment", at);
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
/** Records that waited on `target` and may now have their entity, and theirs in turn. */
|
|
152
|
-
const completeDependents = (target, source, proposed, laterErrors) => {
|
|
153
|
-
const queue = [target];
|
|
154
|
-
while (queue.length > 0) {
|
|
155
|
-
const rows = sql("SELECT DISTINCT r.* FROM record_relations rr JOIN records r ON r.id = rr.record_id WHERE rr.target_id = ? " +
|
|
156
|
-
`AND r.entity_id IS NULL AND r.deleted_at IS NULL AND r.type IN (${PROJECTED_TYPES_SQL})`).all(queue.shift());
|
|
157
|
-
for (const row of rows) {
|
|
158
|
-
try {
|
|
159
|
-
const done = write(database, () => project(row, source));
|
|
160
|
-
if (done.proposed) {
|
|
161
|
-
proposed.push(done.proposed);
|
|
162
|
-
queue.push(Number(row.id));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
if (!(error instanceof CliError))
|
|
167
|
-
throw error;
|
|
168
|
-
laterErrors.push({
|
|
169
|
-
pointer: "",
|
|
170
|
-
code: codeOf(error),
|
|
171
|
-
message: `${String(row.type)} ${String(row.external_id)} waits: ${error.message}`,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
const storedRelations = (recordId) => sql("SELECT role, target_type, target_external_id FROM record_relations WHERE record_id = ?")
|
|
178
|
-
.all(recordId)
|
|
179
|
-
.map((row) => ({
|
|
180
|
-
role: String(row.role),
|
|
181
|
-
type: String(row.target_type),
|
|
182
|
-
external_id: String(row.target_external_id),
|
|
183
|
-
}));
|
|
184
|
-
const relate = (recordId, accountId, relations, at) => {
|
|
185
|
-
sql("DELETE FROM record_relations WHERE record_id = ?").run(recordId);
|
|
186
|
-
for (const relation of relations)
|
|
187
|
-
sql("INSERT OR IGNORE INTO record_relations (record_id, role, target_type, target_external_id, target_id, " +
|
|
188
|
-
"created_at, amount) VALUES (?, ?, ?, ?, (SELECT id FROM records WHERE account_id = ? AND type = ? " +
|
|
189
|
-
"AND external_id = ?), ?, ?)").run(recordId, relation.role, relation.type, relation.external_id, accountId, relation.type, relation.external_id, at, relation.amount ?? null);
|
|
190
|
-
};
|
|
191
|
-
const writeOne = (accountId, source, { record }, proposed) => {
|
|
192
|
-
const stored = sql("SELECT * FROM records WHERE account_id = ? AND type = ? AND external_id = ?").get(accountId, record.type, record.external_id);
|
|
193
|
-
const relations = record.relations ?? [];
|
|
194
|
-
const fingerprint = record.operation === "upsert" ? recordFingerprint(record.fields ?? {}, relations) : null;
|
|
195
|
-
const stale = (why) => refusal(why, "record.stale-revision", "revision");
|
|
196
|
-
if (stored && stored.revision != null) {
|
|
197
|
-
const held = Number(stored.revision);
|
|
198
|
-
if (record.revision === undefined)
|
|
199
|
-
stale(`the store holds revision ${held}: send the record's revision`);
|
|
200
|
-
else if (record.revision < held)
|
|
201
|
-
stale(`revision ${record.revision} is older than the stored ${held}`);
|
|
202
|
-
else if (record.revision === held && fingerprint !== null && fingerprint !== stored.fingerprint)
|
|
203
|
-
stale(`revision ${held} is stored with other content: a change needs a higher revision`);
|
|
204
|
-
}
|
|
205
|
-
const time = now();
|
|
206
|
-
const revision = record.revision ?? (stored?.revision == null ? null : Number(stored.revision));
|
|
207
|
-
if (record.operation === "delete") {
|
|
208
|
-
if (!stored)
|
|
209
|
-
return refusal(`no ${record.type} ${record.external_id} to delete`, "record.not-found", "external_id");
|
|
210
|
-
if (stored.deleted_at != null)
|
|
211
|
-
return { status: "unchanged", id: Number(stored.id) };
|
|
212
|
-
sql("UPDATE records SET deleted_at = ?, updated_at = ?, revision = ?, batch_id = ? WHERE id = ?").run(time, time, revision, source.batch_id, Number(stored.id));
|
|
213
|
-
return { status: "deleted", id: Number(stored.id), flagged: stored.entity_id != null };
|
|
214
|
-
}
|
|
215
|
-
const fields = JSON.stringify(record.fields);
|
|
216
|
-
if (stored && stored.fingerprint === fingerprint && stored.deleted_at == null)
|
|
217
|
-
return { status: "unchanged", id: Number(stored.id) };
|
|
218
|
-
checkShares(record);
|
|
219
|
-
// Whether the payment the record stands for differs in more than whom it settles, against the stored version.
|
|
220
|
-
const beyondSettles = stored?.entity_id != null &&
|
|
221
|
-
(stored.projected_fingerprint !== stored.fingerprint ||
|
|
222
|
-
unsettled(JSON.parse(String(stored.fields)), storedRelations(Number(stored.id))) !==
|
|
223
|
-
unsettled(record.fields ?? {}, relations));
|
|
224
|
-
const id = stored
|
|
225
|
-
? Number(stored.id)
|
|
226
|
-
: Number(sql("INSERT INTO records (account_id, type, external_id, fields, revision, fingerprint, batch_id, created_at, " +
|
|
227
|
-
"updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id").get(accountId, record.type, record.external_id, fields, revision, fingerprint, source.batch_id, time, time)
|
|
228
|
-
?.id);
|
|
229
|
-
if (stored)
|
|
230
|
-
sql("UPDATE records SET fields = ?, revision = ?, fingerprint = ?, batch_id = ?, updated_at = ?, deleted_at = NULL " +
|
|
231
|
-
"WHERE id = ?").run(fields, revision, fingerprint, source.batch_id, time, id);
|
|
232
|
-
else
|
|
233
|
-
sql("UPDATE record_relations SET target_id = ? WHERE target_id IS NULL AND target_type = ? AND target_external_id = ? " +
|
|
234
|
-
"AND record_id IN (SELECT id FROM records WHERE account_id = ?)").run(id, record.type, record.external_id, accountId);
|
|
235
|
-
relate(id, accountId, relations, time);
|
|
236
|
-
let projected = false;
|
|
237
|
-
let flagged = stored?.entity_id != null && stored.projected_fingerprint !== fingerprint;
|
|
238
|
-
if (isProjected(record.type) && stored?.entity_id == null) {
|
|
239
|
-
const done = project({ id, type: record.type, fields, account_id: accountId }, source);
|
|
240
|
-
if (done.proposed)
|
|
241
|
-
proposed.push(done.proposed);
|
|
242
|
-
projected = done.proposed !== undefined;
|
|
243
|
-
}
|
|
244
|
-
else if (record.type === "payment" && stored?.entity_type === "payment" && stored.deleted_at == null) {
|
|
245
|
-
const ref = `payment:${Number(stored.entity_id)}`;
|
|
246
|
-
if (resettle(id, ref)) {
|
|
247
|
-
proposed.push(ref);
|
|
248
|
-
if (!beyondSettles) {
|
|
249
|
-
sql("UPDATE records SET projected_fingerprint = fingerprint WHERE id = ?").run(id);
|
|
250
|
-
flagged = false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return {
|
|
255
|
-
status: stored ? "updated" : "created",
|
|
256
|
-
id,
|
|
257
|
-
flagged,
|
|
258
|
-
// Records waiting on this one move only when it has an entity: made now, or back from a delete.
|
|
259
|
-
complete: projected || (stored?.deleted_at != null && stored.entity_id != null),
|
|
260
|
-
};
|
|
261
|
-
};
|
|
262
|
-
const missingOf = (id) => {
|
|
263
|
-
const row = sql("SELECT type, entity_id, deleted_at FROM records WHERE id = ?").get(id);
|
|
264
|
-
if (!row || row.entity_id != null || row.deleted_at != null || !isProjected(row.type))
|
|
265
|
-
return null;
|
|
266
|
-
const { missing } = relatedOf(id, row.type);
|
|
267
|
-
return missing.length > 0 ? missing : null;
|
|
268
|
-
};
|
|
269
|
-
const ingest = (source, records, chunk) => {
|
|
270
|
-
const outcomes = [];
|
|
271
|
-
const proposed = [];
|
|
272
|
-
const flagged = [];
|
|
273
|
-
const laterErrors = [];
|
|
274
|
-
const kept = [];
|
|
275
|
-
for (let start = 0; start < records.length; start += chunk) {
|
|
276
|
-
write(database, () => {
|
|
277
|
-
const accountId = accountPk(context, { provider: source.provider, account: source.account });
|
|
278
|
-
const complete = [];
|
|
279
|
-
for (const item of records.slice(start, start + chunk)) {
|
|
280
|
-
try {
|
|
281
|
-
const done = isProjected(item.record.type)
|
|
282
|
-
? write(database, () => writeOne(accountId, source, item, proposed))
|
|
283
|
-
: writeOne(accountId, source, item, proposed);
|
|
284
|
-
outcomes.push({ index: item.index, key: item.record.key, status: done.status });
|
|
285
|
-
if (done.id === undefined)
|
|
286
|
-
continue;
|
|
287
|
-
kept.push({ index: item.index, key: item.record.key, id: done.id });
|
|
288
|
-
if (done.flagged) {
|
|
289
|
-
const row = sql("SELECT entity_type, entity_id FROM records WHERE id = ?").get(done.id);
|
|
290
|
-
flagged.push({
|
|
291
|
-
index: item.index,
|
|
292
|
-
key: item.record.key,
|
|
293
|
-
entity: entityRef(row?.entity_type, row?.entity_id),
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
if (done.complete)
|
|
297
|
-
complete.push(done.id);
|
|
298
|
-
}
|
|
299
|
-
catch (error) {
|
|
300
|
-
if (!(error instanceof CliError))
|
|
301
|
-
throw error;
|
|
302
|
-
const at = error.details?.at ?? "fields";
|
|
303
|
-
const pointer = pointerOf("records", item.index, ...[at].flat());
|
|
304
|
-
outcomes.push({
|
|
305
|
-
index: item.index,
|
|
306
|
-
key: item.record.key,
|
|
307
|
-
status: "refused",
|
|
308
|
-
error: { pointer, code: codeOf(error), message: error.message, key: item.record.key },
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
for (const id of complete)
|
|
313
|
-
completeDependents(id, source, proposed, laterErrors);
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
const waiting = read(database, () => kept.flatMap(({ index, key, id }) => {
|
|
317
|
-
const missing = missingOf(id);
|
|
318
|
-
return missing === null ? [] : [{ index, key, missing }];
|
|
319
|
-
}));
|
|
320
|
-
return { outcomes, proposed: [...new Set(proposed)], waiting, flagged, laterErrors };
|
|
321
|
-
};
|
|
16
|
+
const { database } = context;
|
|
17
|
+
const sql = (text) => database.prepare(text);
|
|
18
|
+
const writes = recordWritesOver(context);
|
|
19
|
+
const { entityRef, project, completeDependents } = writes;
|
|
20
|
+
const run = recordRunOver(context, writes);
|
|
21
|
+
const { pointedAt, remap } = recordRemapOver(context);
|
|
322
22
|
const sourceRecordOf = (row) => ({
|
|
323
23
|
provider: String(row.provider),
|
|
324
24
|
account: String(row.account),
|
|
@@ -327,17 +27,25 @@ export const recordStoreOver = (context) => {
|
|
|
327
27
|
fields: JSON.parse(String(row.fields)),
|
|
328
28
|
revision: row.revision == null ? null : Number(row.revision),
|
|
329
29
|
fingerprint: String(row.fingerprint),
|
|
330
|
-
relations: sql("SELECT role, target_type, target_external_id, target_id, amount FROM record_relations
|
|
331
|
-
"ORDER BY id")
|
|
30
|
+
relations: sql("SELECT role, target_type, target_external_id, target_id, amount, as_role FROM record_relations " +
|
|
31
|
+
"WHERE record_id = ? ORDER BY id")
|
|
332
32
|
.all(Number(row.id))
|
|
333
|
-
.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
33
|
+
.filter((relation) => !isDerived(String(relation.role)))
|
|
34
|
+
.map((relation) => {
|
|
35
|
+
const byRef = relation.target_type === "ref";
|
|
36
|
+
const target = String(relation.target_external_id);
|
|
37
|
+
return {
|
|
38
|
+
role: String(relation.role),
|
|
39
|
+
type: byRef ? target.slice(0, target.indexOf(":")) : String(relation.target_type),
|
|
40
|
+
externalId: byRef ? null : target,
|
|
41
|
+
ref: byRef ? target : null,
|
|
42
|
+
as: relation.as_role == null ? null : String(relation.as_role),
|
|
43
|
+
amount: relation.amount == null ? null : String(relation.amount),
|
|
44
|
+
resolved: byRef || relation.target_id != null,
|
|
45
|
+
};
|
|
46
|
+
}),
|
|
340
47
|
entity: entityRef(row.entity_type, row.entity_id),
|
|
48
|
+
createdEntity: Number(row.created_entity) === 1,
|
|
341
49
|
flagged: row.entity_id != null && (row.deleted_at != null || row.projected_fingerprint !== row.fingerprint),
|
|
342
50
|
batchId: String(row.batch_id),
|
|
343
51
|
createdAt: iso(row.created_at),
|
|
@@ -346,29 +54,26 @@ export const recordStoreOver = (context) => {
|
|
|
346
54
|
});
|
|
347
55
|
const SELECT = "SELECT r.*, a.provider, a.external_id AS account FROM records r JOIN accounts a ON a.id = r.account_id ";
|
|
348
56
|
const rowOf = (key) => sql(`${SELECT}WHERE a.provider = ? AND a.external_id = ? AND r.type = ? AND r.external_id = ?`).get(key.provider, key.account, key.type, key.externalId);
|
|
57
|
+
/** Keeps the first `LIMIT` entries of a list, and says when it dropped one. */
|
|
58
|
+
const capped = (flag) => {
|
|
59
|
+
const list = [];
|
|
60
|
+
const push = (item) => {
|
|
61
|
+
if (list.length < LIMIT)
|
|
62
|
+
list.push(item);
|
|
63
|
+
else
|
|
64
|
+
flag();
|
|
65
|
+
};
|
|
66
|
+
return { list, push };
|
|
67
|
+
};
|
|
349
68
|
return {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
let result;
|
|
354
|
-
const rollback = new Error("dry run");
|
|
355
|
-
try {
|
|
356
|
-
write(database, () => {
|
|
357
|
-
result = ingest(source, records, chunk);
|
|
358
|
-
throw rollback;
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
catch (error) {
|
|
362
|
-
if (error !== rollback)
|
|
363
|
-
throw error;
|
|
364
|
-
}
|
|
365
|
-
return result;
|
|
366
|
-
},
|
|
69
|
+
run: async (source, items, options = {}) => options.dryRun
|
|
70
|
+
? rehearse({ database, client: context.orm.$client }, () => run(source, items, options))
|
|
71
|
+
: run(source, items, options),
|
|
367
72
|
get: async (key) => read(database, () => {
|
|
368
73
|
const row = rowOf(key);
|
|
369
74
|
return row ? sourceRecordOf(row) : undefined;
|
|
370
75
|
}),
|
|
371
|
-
list: async ({ provider, account, type, waiting, flagged, limit = 100 }) => {
|
|
76
|
+
list: async ({ provider, account, type, waiting, unmatched, flagged, limit = 100 }) => {
|
|
372
77
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 500)
|
|
373
78
|
throw new CliError("validation_error", "a record list takes 1–500 items");
|
|
374
79
|
return read(database, () => {
|
|
@@ -376,10 +81,12 @@ export const recordStoreOver = (context) => {
|
|
|
376
81
|
return [];
|
|
377
82
|
const rows = database
|
|
378
83
|
.prepare(`${SELECT}WHERE a.provider = ? AND a.external_id = ? AND (? IS NULL OR r.type = ?) ` +
|
|
379
|
-
|
|
84
|
+
"AND (? IS NULL OR (r.entity_id IS NULL AND r.deleted_at IS NULL AND r.type NOT LIKE 'custom:%' " +
|
|
85
|
+
`AND r.type NOT IN (${IDENTITY_SQL}))) ` +
|
|
86
|
+
`AND (? IS NULL OR (r.entity_id IS NULL AND r.deleted_at IS NULL AND r.type IN (${IDENTITY_SQL}))) ` +
|
|
380
87
|
"AND (? IS NULL OR (r.entity_id IS NOT NULL AND (r.deleted_at IS NOT NULL " +
|
|
381
88
|
"OR r.projected_fingerprint IS NOT r.fingerprint))) ORDER BY r.updated_at DESC, r.id DESC LIMIT ?")
|
|
382
|
-
.all(provider, account, type ?? null, type ?? null, waiting ? 1 : null, flagged ? 1 : null, limit);
|
|
89
|
+
.all(provider, account, type ?? null, type ?? null, waiting ? 1 : null, unmatched ? 1 : null, flagged ? 1 : null, limit);
|
|
383
90
|
return rows.map(sourceRecordOf);
|
|
384
91
|
});
|
|
385
92
|
},
|
|
@@ -388,8 +95,9 @@ export const recordStoreOver = (context) => {
|
|
|
388
95
|
throw new CliError("permission_error", "only the owner says which entity a record is", {
|
|
389
96
|
reason: "record.map-owner-only",
|
|
390
97
|
});
|
|
391
|
-
|
|
392
|
-
const
|
|
98
|
+
let unused = null;
|
|
99
|
+
const proposed = new Set();
|
|
100
|
+
const errors = [];
|
|
393
101
|
write(database, () => {
|
|
394
102
|
const row = rowOf(key);
|
|
395
103
|
if (!row || row.deleted_at != null)
|
|
@@ -397,13 +105,75 @@ export const recordStoreOver = (context) => {
|
|
|
397
105
|
const thing = requiredThing(database, entity, "the entity");
|
|
398
106
|
if (thing.type !== key.type)
|
|
399
107
|
refusal(`a ${key.type} record maps to a ${key.type}:, not ${entity}`, "record.map-type");
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
108
|
+
const same = row.entity_type === thing.type && Number(row.entity_id) === thing.id;
|
|
109
|
+
const from = row.entity_id != null && !same ? { type: String(row.entity_type), id: Number(row.entity_id) } : null;
|
|
110
|
+
if (from !== null) {
|
|
111
|
+
if (Number(row.created_entity) !== 1)
|
|
112
|
+
refusal(`${key.type} ${key.externalId} is already ${entityRef(row.entity_type, row.entity_id)}`, "record.mapped");
|
|
113
|
+
remap(row, from, thing);
|
|
114
|
+
if (!pointedAt(from.type, from.id))
|
|
115
|
+
unused = entityRef(from.type, from.id);
|
|
116
|
+
}
|
|
117
|
+
else
|
|
118
|
+
sql("UPDATE records SET entity_type = ?, entity_id = ?, created_entity = 0, " +
|
|
119
|
+
"projected_fingerprint = fingerprint WHERE id = ?").run(thing.type, thing.id, Number(row.id));
|
|
403
120
|
const source = { provider: key.provider, account: key.account, batch_id: String(row.batch_id) };
|
|
404
|
-
completeDependents(Number(row.id), source, proposed,
|
|
121
|
+
completeDependents(Number(row.id), source, (ref) => proposed.add(ref), (error) => errors.push(error));
|
|
122
|
+
});
|
|
123
|
+
return read(database, () => ({
|
|
124
|
+
...sourceRecordOf(rowOf(key)),
|
|
125
|
+
unused,
|
|
126
|
+
proposed: [...proposed],
|
|
127
|
+
errors,
|
|
128
|
+
}));
|
|
129
|
+
},
|
|
130
|
+
match: async ({ provider, account }) => {
|
|
131
|
+
let truncated = false;
|
|
132
|
+
const flag = () => {
|
|
133
|
+
truncated = true;
|
|
134
|
+
};
|
|
135
|
+
const unmatched = capped(flag);
|
|
136
|
+
const errors = capped(flag);
|
|
137
|
+
const proposed = new Set();
|
|
138
|
+
const counts = { linked: 0, created: 0 };
|
|
139
|
+
write(database, () => {
|
|
140
|
+
const accountId = findAccountPk(context, { provider, account });
|
|
141
|
+
if (accountId === undefined)
|
|
142
|
+
return;
|
|
143
|
+
const rows = database
|
|
144
|
+
.prepare("SELECT * FROM records WHERE account_id = ? AND entity_id IS NULL AND deleted_at IS NULL " +
|
|
145
|
+
`AND type IN (${IDENTITY_SQL}) ORDER BY id`)
|
|
146
|
+
.all(accountId);
|
|
147
|
+
for (const row of rows) {
|
|
148
|
+
const source = { provider, account, batch_id: String(row.batch_id) };
|
|
149
|
+
const recordKey = { provider, account, type: String(row.type), externalId: String(row.external_id) };
|
|
150
|
+
try {
|
|
151
|
+
const done = write(database, () => project(row, source));
|
|
152
|
+
if (done.unmatched)
|
|
153
|
+
unmatched.push({ key: recordKey, ...done.unmatched });
|
|
154
|
+
if (!done.made)
|
|
155
|
+
continue;
|
|
156
|
+
const created = sql("SELECT created_entity FROM records WHERE id = ?").get(Number(row.id))?.created_entity;
|
|
157
|
+
counts[Number(created) === 1 ? "created" : "linked"] += 1;
|
|
158
|
+
completeDependents(Number(row.id), source, (ref) => {
|
|
159
|
+
if (proposed.size < LIMIT)
|
|
160
|
+
proposed.add(ref);
|
|
161
|
+
else if (!proposed.has(ref))
|
|
162
|
+
flag();
|
|
163
|
+
}, errors.push);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (!(error instanceof CliError))
|
|
167
|
+
throw error;
|
|
168
|
+
errors.push({
|
|
169
|
+
pointer: "",
|
|
170
|
+
code: codeOf(error),
|
|
171
|
+
message: `${recordKey.type} ${recordKey.externalId}: ${error.message}`,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
405
175
|
});
|
|
406
|
-
return
|
|
176
|
+
return { ...counts, unmatched: unmatched.list, proposed: [...proposed], errors: errors.list, truncated };
|
|
407
177
|
},
|
|
408
178
|
};
|
|
409
179
|
};
|
|
@@ -9,9 +9,10 @@ export interface RefRead extends RefSummary {
|
|
|
9
9
|
* Every ref read back in one statement per kind present, keyed by the text passed and in its order. A bad ref is
|
|
10
10
|
* `unknown` and a ref the store lacks is `unavailable`: one bad row must not fail a page of them.
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export interface RefReadOptions {
|
|
13
13
|
excerpt?: boolean;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}) => Map<string,
|
|
14
|
+
/** The store's clock, for a title that shows what is in force today. */
|
|
15
|
+
now?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const refReadsOf: (database: CacheDatabase, texts: readonly string[], { excerpt, now }?: RefReadOptions) => Map<string, RefRead>;
|
|
18
|
+
export declare const refSummariesOf: (database: CacheDatabase, texts: readonly string[], options?: RefReadOptions) => Map<string, RefSummary>;
|