@wirecat/cli-core 0.732.0 → 0.734.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/cli/messenger/search-command.js +1 -0
  3. package/dist/cli/option-hints.d.ts +7 -0
  4. package/dist/cli/option-hints.js +25 -0
  5. package/dist/cli/program.js +13 -23
  6. package/dist/cli/steps.d.ts +2 -0
  7. package/dist/cli/steps.js +15 -0
  8. package/dist/crm/cli/activities.d.ts +12 -2
  9. package/dist/crm/cli/activities.js +101 -6
  10. package/dist/crm/cli/changes.d.ts +3 -0
  11. package/dist/crm/cli/changes.js +11 -2
  12. package/dist/crm/cli/index.d.ts +3 -2
  13. package/dist/crm/index.d.ts +2 -2
  14. package/dist/crm/index.js +2 -2
  15. package/dist/crm/testing/index.d.ts +1 -1
  16. package/dist/crm/testing/source.d.ts +8 -0
  17. package/dist/crm/testing/source.js +56 -2
  18. package/dist/crm/writer.d.ts +30 -1
  19. package/dist/crm/writer.js +4 -0
  20. package/dist/crm/writes.d.ts +34 -2
  21. package/dist/crm/writes.js +100 -0
  22. package/dist/errors/reasons.js +1 -0
  23. package/dist/ports/messenger.d.ts +1 -1
  24. package/dist/services/archive.js +3 -2
  25. package/dist/services/embeddings-search.js +29 -3
  26. package/dist/store/conversations.d.ts +16 -0
  27. package/dist/store/conversations.js +7 -0
  28. package/dist/store/sqlite/account-purge.js +8 -15
  29. package/dist/store/sqlite/conversations.d.ts +16 -0
  30. package/dist/store/sqlite/conversations.js +49 -1
  31. package/dist/store/sqlite/erase-plan.js +27 -5
  32. package/dist/store/sqlite/organization-erase.d.ts +2 -1
  33. package/dist/store/sqlite/organization-erase.js +2 -1
  34. package/dist/store/sqlite/person-erase.d.ts +6 -3
  35. package/dist/store/sqlite/person-erase.js +33 -17
  36. package/package.json +1 -1
@@ -4,7 +4,7 @@ import { count, ErasePlan } from "./erase-plan.js";
4
4
  import { forgetDanglingEvidence } from "./evidence-signature.js";
5
5
  import { forgetErasedLinks } from "./identity-link-rows.js";
6
6
  import { forgetErasedSplits } from "./identity-split-proposals.js";
7
- import { currentPerson } from "./merged-persons.js";
7
+ import { currentPerson, samePersons } from "./merged-persons.js";
8
8
  import { ownerOnly } from "./person-merges.js";
9
9
  import { forgetErasedTestData } from "./test-people.js";
10
10
  const personOf = (context, uid) => {
@@ -16,7 +16,8 @@ const personOf = (context, uid) => {
16
16
  };
17
17
  /**
18
18
  * Deletes a person and what memo knows of them alone: their identities, the tags, links, aliases and mentions that
19
- * name them, their involvements. A fact, a note, a record or a task that names them stays and loses the name. A
19
+ * name them, their involvements, the owner's notes about them, and the people merged into them earlier. A fact, a
20
+ * record or a task that names them stays and loses the name. A
20
21
  * message, mail or meeting is the source's: its sender stays as an identity with no person. Refused for the owner,
21
22
  * and while an invoice, order, subscription or a row they wrote cannot be without them. `apply: false` answers the
22
23
  * same without changing anything.
@@ -44,12 +45,14 @@ export const erasePerson = (context, uid, by, apply) => {
44
45
  const going = linked.filter(({ id }) => !named.has(id));
45
46
  const kept = linked.filter(({ id }) => named.has(id));
46
47
  const goingIds = JSON.stringify(going.map(({ id }) => id));
47
- const plan = new ErasePlan(database).pointers("person", "?", [person]).pointers("identity", theirs, [goingIds]);
48
+ const chain = samePersons(database, person);
49
+ const chainIds = JSON.stringify(chain);
50
+ const plan = new ErasePlan(database).pointers("person", theirs, [chainIds]).pointers("identity", theirs, [goingIds]);
48
51
  const { deleted, detached, blocked } = plan;
49
- const involvements = count(database, `involvements WHERE person_id = ? OR identity_id IN (${theirs})`, person, goingIds);
52
+ const involvements = count(database, `involvements WHERE person_id IN (${theirs}) OR identity_id IN (${theirs})`, chainIds, goingIds);
50
53
  if (involvements > 0)
51
54
  deleted["involvements.person"] = (deleted["involvements.person"] ?? 0) + involvements;
52
- const bots = count(database, "bots WHERE owner_person_id = ?", person);
55
+ const bots = count(database, `bots WHERE owner_person_id IN (${theirs})`, chainIds);
53
56
  if (bots > 0)
54
57
  detached["bots.owner_person"] = bots;
55
58
  if (blocked.length > 0)
@@ -58,6 +61,7 @@ export const erasePerson = (context, uid, by, apply) => {
58
61
  person: `person:${person}`,
59
62
  name: row?.name == null ? null : String(row.name),
60
63
  erased,
64
+ merged: chain.filter((one) => one !== person).map((one) => `person:${one}`),
61
65
  identities: going.map(({ ref }) => ref),
62
66
  kept: kept.map(({ id, ref }) => ({ identity: ref, references: named.get(id) ?? 0 })),
63
67
  deleted,
@@ -66,17 +70,21 @@ export const erasePerson = (context, uid, by, apply) => {
66
70
  if (!apply)
67
71
  return answer(false);
68
72
  plan.run();
69
- database.prepare(`DELETE FROM involvements WHERE person_id = ? OR identity_id IN (${theirs})`).run(person, goingIds);
70
- database.prepare("UPDATE bots SET owner_person_id = NULL WHERE owner_person_id = ?").run(person);
73
+ database
74
+ .prepare(`DELETE FROM involvements WHERE person_id IN (${theirs}) OR identity_id IN (${theirs})`)
75
+ .run(chainIds, goingIds);
76
+ database.prepare(`UPDATE bots SET owner_person_id = NULL WHERE owner_person_id IN (${theirs})`).run(chainIds);
71
77
  for (const table of ["account_identities", "organization_identities", "identity_revisions"])
72
78
  database.prepare(`DELETE FROM ${table} WHERE identity_id IN (${theirs})`).run(goingIds);
73
79
  database
74
- .prepare(`DELETE FROM identity_link_events WHERE to_person_id = ? OR identity_id IN (${theirs})`)
75
- .run(person, goingIds);
76
- database.prepare("UPDATE identity_link_events SET from_person_id = NULL WHERE from_person_id = ?").run(person);
77
- database.prepare("DELETE FROM identity_links WHERE person_id = ?").run(person);
80
+ .prepare(`DELETE FROM identity_link_events WHERE to_person_id IN (${theirs}) OR identity_id IN (${theirs})`)
81
+ .run(chainIds, goingIds);
82
+ database
83
+ .prepare(`UPDATE identity_link_events SET from_person_id = NULL WHERE from_person_id IN (${theirs})`)
84
+ .run(chainIds);
85
+ database.prepare(`DELETE FROM identity_links WHERE person_id IN (${theirs})`).run(chainIds);
78
86
  database.prepare(`DELETE FROM identities WHERE id IN (${theirs})`).run(goingIds);
79
- database.prepare("DELETE FROM persons WHERE id = ?").run(person);
87
+ database.prepare(`DELETE FROM persons WHERE id IN (${theirs})`).run(chainIds);
80
88
  forgetErasedLinks(database);
81
89
  forgetErasedSplits(database);
82
90
  forgetErasedTestData(database);
@@ -92,8 +100,8 @@ export const importedPeople = (database, accountKey) => database
92
100
  .map(({ id }) => Number(id));
93
101
  /**
94
102
  * After a purge, the people only its records made go too: nothing else names them, and no message, mail or meeting
95
- * names their identities; their involvements are derived and go with them. One the owner tagged, linked or gave a
96
- * task to stays.
103
+ * names their identities; their involvements are derived and go with them. One the owner tagged, linked, gave a task
104
+ * to or merged with another person stays: a merge says the owner knows them from somewhere else too.
97
105
  */
98
106
  export const eraseImportedPeople = (context, people) => {
99
107
  const { database } = context;
@@ -104,8 +112,16 @@ export const eraseImportedPeople = (context, people) => {
104
112
  const params = Array.from({ length: others.split("IN (?)").length - 1 }, () => person);
105
113
  if (database.prepare(`SELECT 1 FROM (${others}) LIMIT 1`).get(...params) !== undefined)
106
114
  continue;
107
- const plan = erasePerson(context, String(person), "owner", false);
108
- if (plan.kept.length === 0)
109
- erasePerson(context, String(person), "owner", true);
115
+ if (samePersons(database, person).length > 1)
116
+ continue;
117
+ try {
118
+ const plan = erasePerson(context, String(person), "owner", false);
119
+ if (plan.kept.length === 0)
120
+ erasePerson(context, String(person), "owner", true);
121
+ }
122
+ catch (error) {
123
+ if (!(error instanceof CliError))
124
+ throw error;
125
+ }
110
126
  }
111
127
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.732.0",
3
+ "version": "0.734.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",