@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
|
@@ -2,9 +2,10 @@ import type { CrmValue } from "../../domain/crm.js";
|
|
|
2
2
|
import { type DealKind, type DealRole, type DealStatus, type StageOutcome } from "../../domain/deals.js";
|
|
3
3
|
import type { AccountKey } from "../types.js";
|
|
4
4
|
import { type ProposedByFilter } from "./actors.js";
|
|
5
|
-
import { type Party } from "./finance.js";
|
|
6
5
|
import { type Author } from "./memories.js";
|
|
7
6
|
import type { StoreContext } from "./open.js";
|
|
7
|
+
import { type AuthorInfo, type Party } from "./reviewed.js";
|
|
8
|
+
import { type StageAmounts } from "./stage-amounts.js";
|
|
8
9
|
export interface PipelineStage {
|
|
9
10
|
name: string;
|
|
10
11
|
position: number;
|
|
@@ -27,7 +28,7 @@ export interface Pipeline {
|
|
|
27
28
|
stages: PipelineStage[];
|
|
28
29
|
createdAt: string;
|
|
29
30
|
}
|
|
30
|
-
export interface FunnelStage extends PipelineStage {
|
|
31
|
+
export interface FunnelStage extends PipelineStage, StageAmounts {
|
|
31
32
|
/** Rows that got this far: entered this stage or a later one that is not lost, or were won. */
|
|
32
33
|
reached: number;
|
|
33
34
|
/** `reached` of the next stage that is not lost over this stage's, 0–1; `null` for the last or an empty one. */
|
|
@@ -83,12 +84,7 @@ export interface Deal {
|
|
|
83
84
|
/** A CRM copy's own fields by code, as the CRM labels them; empty on the owner's own. */
|
|
84
85
|
providerMetadata: Record<string, CrmValue>;
|
|
85
86
|
people: DealPerson[];
|
|
86
|
-
author:
|
|
87
|
-
type: "person" | "bot";
|
|
88
|
-
id: string;
|
|
89
|
-
name: string | null;
|
|
90
|
-
kind: "agent" | "rule" | null;
|
|
91
|
-
};
|
|
87
|
+
author: AuthorInfo;
|
|
92
88
|
model: string | null;
|
|
93
89
|
source: string;
|
|
94
90
|
reason: string | null;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, dealLine, STAGE_OUTCOMES, } from "../../domain/deals.js";
|
|
3
3
|
import { currencyOf, formatDecimal, minorUnits, scaleOf } from "../../domain/money.js";
|
|
4
|
+
import { notOverriddenSql } from "../../domain/relations.js";
|
|
4
5
|
import { fold } from "../normalize.js";
|
|
5
6
|
import { proposedBySql } from "./actors.js";
|
|
6
|
-
import { isoDate, oneOf, refuse, reviewedRowsOver, text } from "./finance.js";
|
|
7
7
|
import { linkKind } from "./link-kinds.js";
|
|
8
8
|
import { authorActor, authorOf, evidenceOf, linkEvidence, projectId, projectOf } from "./memories.js";
|
|
9
9
|
import { requiredThing } from "./notes.js";
|
|
10
|
+
import { isoDate, limitOf, oneOf, refuse, reviewedRowsOver, text } from "./reviewed.js";
|
|
11
|
+
import { stageAmountsOf } from "./stage-amounts.js";
|
|
10
12
|
import { write } from "./transaction.js";
|
|
11
13
|
const TABLES = { deal: "deals", lead: "leads" };
|
|
12
14
|
const itemsSql = (kind) => "SELECT d.*, s.name AS stage_name, s.pipeline_id, p.name AS pipeline_name, b.name AS author_name, " +
|
|
@@ -45,7 +47,7 @@ export const dealOperationsOver = (context) => {
|
|
|
45
47
|
const today = () => new Date(now()).toISOString().slice(0, 10);
|
|
46
48
|
const peopleOf = (kind, id) => database
|
|
47
49
|
.prepare(`SELECT to_id, role FROM links WHERE from_type = ? AND from_id = ? AND kind = ${linkKind("related-to")} ` +
|
|
48
|
-
|
|
50
|
+
`AND to_type = 'person' AND to_id IS NOT NULL AND deleted_at IS NULL AND ${notOverriddenSql("links")} ORDER BY id`)
|
|
49
51
|
.all(kind, id)
|
|
50
52
|
.map((row) => ({ ...partyOf("person", row.to_id), role: row.role }));
|
|
51
53
|
const itemOf = (kind) => (row) => {
|
|
@@ -196,6 +198,7 @@ export const dealOperationsOver = (context) => {
|
|
|
196
198
|
.prepare("SELECT id, position, outcome FROM pipeline_stages WHERE pipeline_id = ? ORDER BY position, id")
|
|
197
199
|
.all(Number(pipeline.id));
|
|
198
200
|
const order = new Map(stages.map((stage, at) => [Number(stage.id), at]));
|
|
201
|
+
const standing = stageAmountsOf(context, kind, stages.map((stage) => Number(stage.id)), cutoff);
|
|
199
202
|
const lostStage = new Set(stages.filter((stage) => stage.outcome === "lost").map((stage) => Number(stage.id)));
|
|
200
203
|
const entered = new Map();
|
|
201
204
|
for (const change of database
|
|
@@ -221,7 +224,7 @@ export const dealOperationsOver = (context) => {
|
|
|
221
224
|
const conversion = lostStage.has(Number(stages[at]?.id)) || next === -1 || reached === 0
|
|
222
225
|
? null
|
|
223
226
|
: Math.round((reachedAt(next) / reached) * 1000) / 1000;
|
|
224
|
-
return { ...stage, reached, conversion };
|
|
227
|
+
return { ...stage, reached, conversion, ...standing[at] };
|
|
225
228
|
});
|
|
226
229
|
const won = items.filter((item) => item.status === "won").length;
|
|
227
230
|
return {
|
|
@@ -334,7 +337,7 @@ export const dealOperationsOver = (context) => {
|
|
|
334
337
|
"close_date, closed_date, author_type, author_id, model, source, metadata, created_at, updated_at) " +
|
|
335
338
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id")
|
|
336
339
|
.get(title, organization?.id ?? null, input.project === undefined ? null : projectId(database, input.project), Number(stage.id), status, currency, amount, closeDate, status === "open" ? null : today(), actor.type, actor.id, model, source, reason === null ? null : JSON.stringify({ reason }), at, at)?.id);
|
|
337
|
-
const link = database.prepare("INSERT INTO links (from_type, from_id, to_type, to_id, kind, role, source, confirmed, created_at, author, " +
|
|
340
|
+
const link = database.prepare("INSERT OR IGNORE INTO links (from_type, from_id, to_type, to_id, kind, role, source, confirmed, created_at, author, " +
|
|
338
341
|
`updated_at) VALUES (?, ?, 'person', ?, ${linkKind("related-to")}, ?, ?, 1, ?, ?, ?)`);
|
|
339
342
|
for (const person of persons)
|
|
340
343
|
link.run(kind, made, person.id, person.role, owner ? "owner" : "suggested", at, owner ? "owner" : "agent", at);
|
|
@@ -357,7 +360,7 @@ export const dealOperationsOver = (context) => {
|
|
|
357
360
|
const own = scope === "own" ? 1 : 0;
|
|
358
361
|
const provider = scope === undefined || scope === "own" ? null : scope.provider;
|
|
359
362
|
const account = scope === undefined || scope === "own" ? null : scope.account;
|
|
360
|
-
const limit =
|
|
363
|
+
const limit = limitOf(filter.limit);
|
|
361
364
|
return database
|
|
362
365
|
.prepare(`${itemsSql(kind)} WHERE d.deleted_at IS NULL AND (? IS NULL OR d.status = ?) ` +
|
|
363
366
|
"AND (? IS NULL OR d.project_id = ?) AND (? IS NULL OR s.name_folded = ?) AND (? IS NULL OR p.id = ?) " +
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { filesAccountSql } from "../../../domain/providers.js";
|
|
2
|
+
import { ADDED_PROVIDER, filesAccountSql } from "../../../domain/providers.js";
|
|
3
3
|
import { digest } from "../../document-transfer/digest.js";
|
|
4
4
|
import { referenceOfThing, storedThing } from "../things.js";
|
|
5
5
|
import { read } from "../transaction.js";
|
|
@@ -165,7 +165,7 @@ export const transferSnapshot = (database, collection) => read(database, () => {
|
|
|
165
165
|
}
|
|
166
166
|
if (thing.type === "document") {
|
|
167
167
|
const doc = database
|
|
168
|
-
.prepare(`SELECT a.provider,a.external_id AS account,a.name,d.external_id,d.body,d.content_hash,d.deleted_at FROM documents d JOIN accounts a ON a.id=d.account_id WHERE d.id=? AND ${filesAccountSql("a.provider")}`)
|
|
168
|
+
.prepare(`SELECT a.provider,a.external_id AS account,a.name,d.external_id,d.body,d.content_hash,d.deleted_at FROM documents d JOIN accounts a ON a.id=d.account_id WHERE d.id=? AND ${filesAccountSql("a.provider")} AND a.provider<>'${ADDED_PROVIDER}'`)
|
|
169
169
|
.get(thing.id);
|
|
170
170
|
if (doc) {
|
|
171
171
|
item.collection = collectionNameOf({ provider: doc.provider, external_id: doc.account, name: doc.name });
|
|
@@ -143,6 +143,8 @@ const addressIdentity = (database, orm, accountId, { address, name }, now) => {
|
|
|
143
143
|
return id;
|
|
144
144
|
};
|
|
145
145
|
const identityOf = (database, { address, name }, now) => {
|
|
146
|
+
// Every writer of an e-mail identity (and of identities.email) stores trim().toLowerCase(): the records import
|
|
147
|
+
// matches addresses by plain equality on it, through the index.
|
|
146
148
|
const key = address.trim().toLowerCase();
|
|
147
149
|
const found = database
|
|
148
150
|
.prepare("SELECT id, name FROM identities WHERE provider = 'email' AND external_id = ?")
|
|
@@ -4,13 +4,26 @@ import type { CacheDatabase } from "../driver.js";
|
|
|
4
4
|
* a new type adds it here first; `entity-types.test.ts` holds every literal in the store's SQL to this list.
|
|
5
5
|
*/
|
|
6
6
|
export declare const ENTITY_TABLES: {
|
|
7
|
+
readonly invoice: "invoices";
|
|
8
|
+
readonly payment: "payments";
|
|
9
|
+
readonly person: "persons";
|
|
10
|
+
readonly organization: "organizations";
|
|
11
|
+
readonly project: "projects";
|
|
12
|
+
readonly order: "orders";
|
|
13
|
+
readonly product: "catalog_items";
|
|
14
|
+
readonly contract: "contracts";
|
|
15
|
+
readonly subscription: "subscriptions";
|
|
16
|
+
readonly wallet: "financial_accounts";
|
|
17
|
+
readonly transaction: "financial_transactions";
|
|
18
|
+
readonly deal: "deals";
|
|
19
|
+
readonly lead: "leads";
|
|
20
|
+
readonly pipeline: "pipelines";
|
|
7
21
|
readonly account: "accounts";
|
|
8
22
|
readonly attachment: "attachments";
|
|
9
23
|
readonly bot: "bots";
|
|
10
24
|
readonly calendar_entry: "calendar_entries";
|
|
11
25
|
readonly chat: "chats";
|
|
12
26
|
readonly conversation: "conversations";
|
|
13
|
-
readonly deal: "deals";
|
|
14
27
|
readonly document: "documents";
|
|
15
28
|
readonly document_picture: "documents";
|
|
16
29
|
readonly email: "emails";
|
|
@@ -21,21 +34,13 @@ export declare const ENTITY_TABLES: {
|
|
|
21
34
|
readonly file: "files";
|
|
22
35
|
readonly identity: "identities";
|
|
23
36
|
readonly image: "attachments";
|
|
24
|
-
readonly invoice: "invoices";
|
|
25
|
-
readonly lead: "leads";
|
|
26
37
|
readonly meeting: "meetings";
|
|
27
38
|
readonly meeting_transcript: "meeting_transcripts";
|
|
28
39
|
readonly meeting_transcript_row: "meeting_transcript_rows";
|
|
29
40
|
readonly memory: "memories";
|
|
30
41
|
readonly message: "messages";
|
|
31
42
|
readonly note: "notes";
|
|
32
|
-
readonly order: "orders";
|
|
33
|
-
readonly organization: "organizations";
|
|
34
|
-
readonly payment: "payments";
|
|
35
|
-
readonly person: "persons";
|
|
36
|
-
readonly pipeline: "pipelines";
|
|
37
43
|
readonly place: "places";
|
|
38
|
-
readonly project: "projects";
|
|
39
44
|
readonly tag: "canonical_tags";
|
|
40
45
|
readonly task: "tasks";
|
|
41
46
|
};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import { RECORD_TABLES } from "../../domain/record-types.js";
|
|
1
2
|
/**
|
|
2
3
|
* Every type a `<name>_type` pointer may hold, and the table its `<name>_id` names. A writer that needs
|
|
3
4
|
* a new type adds it here first; `entity-types.test.ts` holds every literal in the store's SQL to this list.
|
|
4
5
|
*/
|
|
5
6
|
export const ENTITY_TABLES = {
|
|
7
|
+
...RECORD_TABLES,
|
|
6
8
|
account: "accounts",
|
|
7
9
|
attachment: "attachments",
|
|
8
10
|
bot: "bots",
|
|
9
11
|
calendar_entry: "calendar_entries",
|
|
10
12
|
chat: "chats",
|
|
11
13
|
conversation: "conversations",
|
|
12
|
-
deal: "deals",
|
|
13
14
|
document: "documents",
|
|
14
15
|
document_picture: "documents",
|
|
15
16
|
email: "emails",
|
|
@@ -20,21 +21,13 @@ export const ENTITY_TABLES = {
|
|
|
20
21
|
file: "files",
|
|
21
22
|
identity: "identities",
|
|
22
23
|
image: "attachments",
|
|
23
|
-
invoice: "invoices",
|
|
24
|
-
lead: "leads",
|
|
25
24
|
meeting: "meetings",
|
|
26
25
|
meeting_transcript: "meeting_transcripts",
|
|
27
26
|
meeting_transcript_row: "meeting_transcript_rows",
|
|
28
27
|
memory: "memories",
|
|
29
28
|
message: "messages",
|
|
30
29
|
note: "notes",
|
|
31
|
-
order: "orders",
|
|
32
|
-
organization: "organizations",
|
|
33
|
-
payment: "payments",
|
|
34
|
-
person: "persons",
|
|
35
|
-
pipeline: "pipelines",
|
|
36
30
|
place: "places",
|
|
37
|
-
project: "projects",
|
|
38
31
|
tag: "canonical_tags",
|
|
39
32
|
task: "tasks",
|
|
40
33
|
};
|
|
@@ -43,7 +36,8 @@ export const isEntityType = (type) => Object.hasOwn(ENTITY_TABLES, type);
|
|
|
43
36
|
export const pointerPairs = (database) => database
|
|
44
37
|
.prepare("SELECT m.name AS tbl, substr(c.name, 1, length(c.name) - 5) AS pointer FROM sqlite_master m " +
|
|
45
38
|
"JOIN pragma_table_info(m.name) c ON c.name LIKE '%\\_type' ESCAPE '\\' " +
|
|
46
|
-
|
|
39
|
+
// record_relations' target_type and target_id name a record of a source, not an entity.
|
|
40
|
+
"WHERE m.type = 'table' AND m.name <> 'record_relations' AND EXISTS (SELECT 1 FROM pragma_table_info(m.name) i " +
|
|
47
41
|
"WHERE i.name = substr(c.name, 1, length(c.name) - 5) || '_id') ORDER BY m.name, c.cid")
|
|
48
42
|
.all()
|
|
49
43
|
.map((row) => ({ table: String(row.tbl), pointer: String(row.pointer) }));
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { CacheDatabase, SqlValue } from "../driver.js";
|
|
2
|
+
import { type Thing } from "./things.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a cited source looks like now, read from its columns only, never its text. `sig` differs whenever the source
|
|
5
|
+
* changed or was deleted in a way this store can see. `rev` finds a version later: for a note or a document its
|
|
6
|
+
* `revision`, whose older body `*_revisions` keeps under that number; for a message or a calendar event the highest id
|
|
7
|
+
* in its `*_revisions` table at the time (`0` for none), so that version's text is the first revision above it, or the
|
|
8
|
+
* current text when there is none; `null` where the store keeps no history.
|
|
9
|
+
*/
|
|
10
|
+
export interface EvidenceSignature {
|
|
11
|
+
sig: string;
|
|
12
|
+
rev: number | null;
|
|
13
|
+
/** Deleted at its source, or the row is gone from the store. */
|
|
14
|
+
deleted: boolean;
|
|
15
|
+
/** The latest change or deletion the store dated; `null` when it dates none, or the row is gone. */
|
|
16
|
+
changedAt: number | null;
|
|
17
|
+
}
|
|
18
|
+
/** What `links.metadata` holds on an `evidence` row. */
|
|
19
|
+
export interface EvidenceMetadata {
|
|
20
|
+
v: 1;
|
|
21
|
+
sig: string;
|
|
22
|
+
/** The version last signed. */
|
|
23
|
+
rev: number | null;
|
|
24
|
+
/** The version cited; it never changes after the link is written. */
|
|
25
|
+
cited_rev: number | null;
|
|
26
|
+
quote?: string;
|
|
27
|
+
checked_at: number;
|
|
28
|
+
/** The cited row was deleted for good: the link keeps no pointer, only the kind it named. */
|
|
29
|
+
gone?: string;
|
|
30
|
+
}
|
|
31
|
+
/** A cited reference, with the words of it the claim rests on. */
|
|
32
|
+
export type EvidenceInput = string | {
|
|
33
|
+
ref: string;
|
|
34
|
+
quote?: string;
|
|
35
|
+
};
|
|
36
|
+
export declare const QUOTE_LIMIT = 500;
|
|
37
|
+
/** How one kind of source is signed, searched for a quote, and read back as it was cited. */
|
|
38
|
+
interface SourceKind {
|
|
39
|
+
signature(database: CacheDatabase, id: number): EvidenceSignature | undefined;
|
|
40
|
+
/** Whether the text holds the quote now; absent where the store keeps no text for the kind. */
|
|
41
|
+
holds?(database: CacheDatabase, id: number, quote: string): boolean;
|
|
42
|
+
/** The text at version `rev`; absent where the store keeps no history for the kind. */
|
|
43
|
+
textAt?(database: CacheDatabase, id: number, rev: number): string | undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The quote still stands in the text word for word, whatever the spacing and line breaks. Case and accents count:
|
|
47
|
+
* the search normalizer folds them, and a changed letter here may be the change that matters.
|
|
48
|
+
*/
|
|
49
|
+
export declare const quoteKept: (quote: string, text: string) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Every kind of source a memory or fact may cite, by its `links.to_type`. An email, a meeting, a person and a project
|
|
52
|
+
* are checked for existence only; any other row an import made from a record follows that record.
|
|
53
|
+
*/
|
|
54
|
+
export declare const SOURCE_KINDS: Partial<Record<string, SourceKind>>;
|
|
55
|
+
export declare const sourceKindOf: (type: string) => SourceKind | undefined;
|
|
56
|
+
/** The signature of a cited row as it is now; a row the store no longer holds is `deleted`. */
|
|
57
|
+
export declare const evidenceSignature: (database: CacheDatabase, thing: Thing) => EvidenceSignature;
|
|
58
|
+
/** Whether a cited row's text holds the quote now; `undefined` where the store keeps no text for its kind. */
|
|
59
|
+
export declare const sourceHolds: (database: CacheDatabase, thing: Thing, quote: string) => boolean | undefined;
|
|
60
|
+
/** The text of a cited row at version `rev`, from its history; `undefined` where there is none. */
|
|
61
|
+
export declare const sourceTextAt: (database: CacheDatabase, thing: Thing, rev: number) => string | undefined;
|
|
62
|
+
/** The reference and quote of one cited source, refusing a quote too long or empty. */
|
|
63
|
+
export declare const evidenceInputOf: (input: EvidenceInput) => {
|
|
64
|
+
ref: string;
|
|
65
|
+
quote?: string;
|
|
66
|
+
};
|
|
67
|
+
/** Refuses a quote the cited source's text does not hold: a claim may rest only on words the source said. */
|
|
68
|
+
export declare const assertQuoted: (database: CacheDatabase, thing: Thing, ref: string, quote: string | undefined) => void;
|
|
69
|
+
/** A new link's metadata: the version cited is the version signed. */
|
|
70
|
+
export declare const evidenceMetadata: (signature: EvidenceSignature, at: number, quote: string | undefined) => EvidenceMetadata;
|
|
71
|
+
/** The stored signature of an `evidence` link, or `undefined` for one written before signatures. */
|
|
72
|
+
export declare const storedEvidenceMetadata: (metadata: unknown) => EvidenceMetadata | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Signs an `evidence` link again. It keeps the quote and the version cited, and the link's own `updated_at` stays, as
|
|
75
|
+
* nothing about the link changed. A link written before signatures takes the version it is signed at as cited.
|
|
76
|
+
*/
|
|
77
|
+
export declare const resignEvidence: (database: CacheDatabase, link: number, signature: EvidenceSignature, at: number, previous: EvidenceMetadata | undefined) => void;
|
|
78
|
+
/** An evidence link whose source went, as `forgetEvidenceTo` left it. */
|
|
79
|
+
export interface ForgottenEvidence {
|
|
80
|
+
link: number;
|
|
81
|
+
from: Thing;
|
|
82
|
+
/** The reference the link named before its source went. */
|
|
83
|
+
ref: string | null;
|
|
84
|
+
citedRev: number | null;
|
|
85
|
+
/** The link was already signed as deleted, so a check reported it then. */
|
|
86
|
+
reported: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Before cited rows go, or a message's text is erased: each evidence link to them drops its quote, which holds the
|
|
90
|
+
* source's words. `ids` is SQL naming the row ids. A row deleted for good also loses its pointer, so the link still
|
|
91
|
+
* says that a source was cited and is gone, and never names another row that takes the same id later; its old
|
|
92
|
+
* reference stays only as `target_text`, which nothing resolves since `target_folded` is empty. A tombstone
|
|
93
|
+
* (`keepPointer`) keeps it, signed as deleted. A memory or fact that still holds gets a `deleted` review in the same
|
|
94
|
+
* write, since the check will not meet a link with no pointer, nor one already signed as deleted; a link already
|
|
95
|
+
* signed as deleted was reported when the check met it.
|
|
96
|
+
*/
|
|
97
|
+
export declare const forgetEvidenceTo: (database: CacheDatabase, type: string, ids: {
|
|
98
|
+
sql: string;
|
|
99
|
+
params: SqlValue[];
|
|
100
|
+
}, at: number, { keepPointer }?: {
|
|
101
|
+
keepPointer?: boolean;
|
|
102
|
+
}) => ForgottenEvidence[];
|
|
103
|
+
/** `forgetEvidenceTo` for one row. */
|
|
104
|
+
export declare const forgetEvidenceToRow: (database: CacheDatabase, thing: Thing, at: number, options?: {
|
|
105
|
+
keepPointer?: boolean;
|
|
106
|
+
}) => ForgottenEvidence[];
|
|
107
|
+
/**
|
|
108
|
+
* After a purge, in its write: forgets evidence still pointing at a row of any citable type that is no longer there,
|
|
109
|
+
* so a kind the purge did not name is not missed. The purge names what it can beforehand, while references resolve.
|
|
110
|
+
*/
|
|
111
|
+
export declare const forgetDanglingEvidence: (database: CacheDatabase, at: number) => ForgottenEvidence[];
|
|
112
|
+
/** Deletes a document row after forgetting the evidence that cites it, so no link is left pointing at a reused id. */
|
|
113
|
+
export declare const deleteDocumentRow: (database: CacheDatabase, id: number, at: number) => void;
|
|
114
|
+
export {};
|