@wirecat/cli-core 0.731.0 → 0.733.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 +28 -0
- package/dist/cli/messenger/search-backend-options.js +6 -2
- package/dist/ports/messenger.d.ts +3 -2
- package/dist/services/archive.js +13 -4
- package/dist/services/server-search.d.ts +5 -0
- package/dist/services/server-search.js +11 -3
- package/dist/store/sqlite/account-purge.js +8 -15
- package/dist/store/sqlite/erase-plan.js +27 -5
- package/dist/store/sqlite/organization-erase.d.ts +2 -1
- package/dist/store/sqlite/organization-erase.js +2 -1
- package/dist/store/sqlite/person-erase.d.ts +6 -3
- package/dist/store/sqlite/person-erase.js +33 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,34 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.733.0 — 23.11.2026
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **Removing an account no longer erases a person its import was merged with.** A person the owner merged with an
|
|
13
|
+
imported one now stays when the account goes, and a person that cannot go no longer makes the whole removal fail.
|
|
14
|
+
- **Deleting a person also deletes the people merged into them earlier**, so their name, aliases and tags do not come
|
|
15
|
+
back as a new person. `PersonErasure` lists them in `merged`.
|
|
16
|
+
- **The owner's notes about a person or an organization go with them** and are listed in the plan, instead of
|
|
17
|
+
blocking the delete. Another table's row that hangs on a pointing row still blocks it.
|
|
18
|
+
- **Removing an account takes the relationships it reported**, and every row that points at its deals and leads
|
|
19
|
+
(a fact, a note, a tag), not only a fixed list of tables.
|
|
20
|
+
- **Thread replies answered in batches are saved again.** 0.732.0 checked for batches before awaiting the answer,
|
|
21
|
+
but the flood wrapper makes every adapter method async, so a messenger that answered in batches had none of its
|
|
22
|
+
replies saved. The answer is now awaited first, and `threadReplies` may return a promise of batches.
|
|
23
|
+
|
|
24
|
+
## 0.732.0 — 23.11.2026
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- **A sync keeps the thread replies it read when it is stopped.** A messenger's `threadReplies` may answer in
|
|
29
|
+
batches (an async iterable); `messages sync` saves each one as it comes and moves the thread point only after the
|
|
30
|
+
last, so a stopped or killed sync keeps what it read and the next one reads from the same point. A plain array still
|
|
31
|
+
works.
|
|
32
|
+
- **A failed server search says what the messenger refused, by its keys.** Each `failed` entry carries
|
|
33
|
+
`error: {code, reason?}`, and the note reads `server search incomplete: search_failed (permission_error:
|
|
34
|
+
oauth.scope-missing)`. The provider's own words still stay out.
|
|
35
|
+
|
|
8
36
|
## 0.731.0 — 23.11.2026
|
|
9
37
|
|
|
10
38
|
### Added
|
|
@@ -25,6 +25,10 @@ export const noteServer = (context, server) => {
|
|
|
25
25
|
return;
|
|
26
26
|
if (server.skipped)
|
|
27
27
|
context.renderer.note(`server search skipped: ${server.skipped} — the answer is the archive's`);
|
|
28
|
-
else if (!server.complete)
|
|
29
|
-
|
|
28
|
+
else if (!server.complete) {
|
|
29
|
+
const reasons = [
|
|
30
|
+
...new Set(server.failed.map(({ reason, error }) => error ? `${reason} (${[error.code, error.reason].filter(Boolean).join(": ")})` : reason)),
|
|
31
|
+
];
|
|
32
|
+
context.renderer.note(`server search incomplete${reasons.length ? `: ${reasons.join(", ")}` : ""}`);
|
|
33
|
+
}
|
|
30
34
|
};
|
|
@@ -301,11 +301,12 @@ export interface ThreadReplies {
|
|
|
301
301
|
/**
|
|
302
302
|
* Replies `history` leaves out, such as Slack's thread replies: those sent after `since` (epoch milliseconds, left
|
|
303
303
|
* out on the chat's first read) to the roots the adapter picks, oldest first. `messages sync` asks after the chat's
|
|
304
|
-
* history and saves them without marking a stretch held.
|
|
304
|
+
* history and saves them without marking a stretch held. A chat with many threads answers in batches: each is saved
|
|
305
|
+
* as it comes, so a stopped or killed sync keeps what it read; the next one reads from the same point again.
|
|
305
306
|
*/
|
|
306
307
|
threadReplies(chatId: Id, window: {
|
|
307
308
|
since?: number;
|
|
308
|
-
}): Promise<Message[]>;
|
|
309
|
+
}): Promise<Message[] | AsyncIterable<Message[]>> | AsyncIterable<Message[]>;
|
|
309
310
|
}
|
|
310
311
|
export interface MessageButtons {
|
|
311
312
|
/** The keyboard one message carries, row by row; a message without one answers `[]`. */
|
package/dist/services/archive.js
CHANGED
|
@@ -437,11 +437,20 @@ const savedReplies = async (connection, store, account, chatId, stop) => {
|
|
|
437
437
|
return 0;
|
|
438
438
|
const startedAt = Date.now();
|
|
439
439
|
const point = Number((await store.sync.syncState(account, threadsKey(chatId)))?.value);
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
440
|
+
// Awaited first: the flood wrapper turns every adapter method async, so batches arrive inside a promise.
|
|
441
|
+
const answer = await connection.threadReplies(chatId, Number.isFinite(point) ? { since: point } : {});
|
|
442
|
+
const batches = Symbol.asyncIterator in answer ? answer : [answer];
|
|
443
|
+
let saved = 0;
|
|
444
|
+
for await (const replies of batches) {
|
|
445
|
+
if (replies.length > 0)
|
|
446
|
+
await store.messages.saveMessages(account, chatId, replies, { via: "history", seenAt: startedAt });
|
|
447
|
+
saved += replies.length;
|
|
448
|
+
// The point moves only once every batch is saved, so a stopped run reads them again.
|
|
449
|
+
if (stop.aborted)
|
|
450
|
+
return saved;
|
|
451
|
+
}
|
|
443
452
|
await store.sync.setSyncState(account, threadsKey(chatId), String(startedAt));
|
|
444
|
-
return
|
|
453
|
+
return saved;
|
|
445
454
|
};
|
|
446
455
|
/** When the message a held stretch starts at was sent: by time the key is the time; by id, the stored message says. */
|
|
447
456
|
const timeOfKey = async (store, account, chatId, key, byTime, fallback) => {
|
|
@@ -29,6 +29,11 @@ export interface ServerSearched {
|
|
|
29
29
|
failed: {
|
|
30
30
|
chat: string | null;
|
|
31
31
|
reason: "rate_limited" | "search_failed" | "time_or_abort_bound";
|
|
32
|
+
/** The messenger's error by its keys alone, such as a missing permission: its words may carry private detail. */
|
|
33
|
+
error?: {
|
|
34
|
+
code: string;
|
|
35
|
+
reason?: string;
|
|
36
|
+
};
|
|
32
37
|
}[];
|
|
33
38
|
/** Candidates stored from their first `SERVER_BOUNDS.textBytes`, without the attachments; a sync reads them whole. */
|
|
34
39
|
partial?: number;
|
|
@@ -9,6 +9,10 @@ export const SERVER_SEARCH_KEY = "messages.server-search";
|
|
|
9
9
|
*/
|
|
10
10
|
export const SERVER_BOUNDS = { timeMs: 5_000, perCall: 100, maxCalls: 3, textBytes: 262_144 };
|
|
11
11
|
export const DEFAULT_BACKEND = "both";
|
|
12
|
+
const keysOf = (error) => {
|
|
13
|
+
const { reason } = error.details;
|
|
14
|
+
return { code: error.code, ...(typeof reason === "string" ? { reason } : {}) };
|
|
15
|
+
};
|
|
12
16
|
export const sourceKey = (chatId, id) => JSON.stringify([chatId, id]);
|
|
13
17
|
const merge = (one, other) => {
|
|
14
18
|
if (one.chat !== undefined && other.chat !== undefined && one.chat !== other.chat)
|
|
@@ -149,10 +153,14 @@ export const searchServer = async (deps, request) => {
|
|
|
149
153
|
const pending = new Set(calls);
|
|
150
154
|
const found = [];
|
|
151
155
|
let open = true;
|
|
152
|
-
const fail = (branch, reason) => {
|
|
156
|
+
const fail = (branch, reason, error) => {
|
|
153
157
|
pending.delete(branch);
|
|
154
158
|
report.complete = false;
|
|
155
|
-
report.failed.push({
|
|
159
|
+
report.failed.push({
|
|
160
|
+
chat: branch.chat ?? null,
|
|
161
|
+
reason,
|
|
162
|
+
...(error instanceof CliError ? { error: keysOf(error) } : {}),
|
|
163
|
+
});
|
|
156
164
|
};
|
|
157
165
|
const ask = async (adapter) => {
|
|
158
166
|
const search = capability(adapter, "searchMessages", "search messages on its server");
|
|
@@ -172,7 +180,7 @@ export const searchServer = async (deps, request) => {
|
|
|
172
180
|
catch (error) {
|
|
173
181
|
if (!open)
|
|
174
182
|
return;
|
|
175
|
-
fail(branch, error instanceof CliError && error.code === "rate_limited" ? "rate_limited" : "search_failed");
|
|
183
|
+
fail(branch, error instanceof CliError && error.code === "rate_limited" ? "rate_limited" : "search_failed", error);
|
|
176
184
|
}
|
|
177
185
|
}));
|
|
178
186
|
};
|
|
@@ -2,6 +2,7 @@ import { dropOrphanPeople, unreferenced } from "./accounts.js";
|
|
|
2
2
|
import { calendarCursorKey, calendarWritesOver } from "./calendar.js";
|
|
3
3
|
import { forgetCalendarRows } from "./calendar-forget.js";
|
|
4
4
|
import { eq, inArray, sql } from "./drizzle/core.js";
|
|
5
|
+
import { ErasePlan } from "./erase-plan.js";
|
|
5
6
|
import { forgetDanglingEvidence, forgetEvidenceTo } from "./evidence-signature.js";
|
|
6
7
|
import { eraseImportedOrganizations, importedOrganizations } from "./organization-erase.js";
|
|
7
8
|
import { eraseImportedPeople, importedPeople } from "./person-erase.js";
|
|
@@ -113,6 +114,9 @@ export const purgeAccount = (context, accountKey) => {
|
|
|
113
114
|
const recordsOf = sql `(SELECT id FROM records WHERE account_id = ${accountKey})`;
|
|
114
115
|
orm.run(sql `DELETE FROM record_relations WHERE record_id IN ${recordsOf} OR target_id IN ${recordsOf}`);
|
|
115
116
|
orm.run(sql `DELETE FROM records WHERE account_id = ${accountKey}`);
|
|
117
|
+
// Relationships the account reported carry its id and no foreign key: left behind, the next account given that id
|
|
118
|
+
// would own them.
|
|
119
|
+
orm.run(sql `DELETE FROM links WHERE account_id = ${accountKey}`);
|
|
116
120
|
orm.delete(accounts).where(eq(accounts.id, accountKey)).run();
|
|
117
121
|
dropOrphanPeople(database, unseenBefore);
|
|
118
122
|
eraseImportedPeople(context, imported);
|
|
@@ -132,21 +136,10 @@ const purgeCrmCopies = (database, accountKey) => {
|
|
|
132
136
|
const leadsOf = "(SELECT id FROM leads WHERE account_id = ?)";
|
|
133
137
|
const pipelinesOf = "(SELECT id FROM pipelines WHERE account_id = ?)";
|
|
134
138
|
const stagesOf = `(SELECT id FROM pipeline_stages WHERE pipeline_id IN ${pipelinesOf})`;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
run(`DELETE FROM links WHERE (from_type = ? AND from_id IN ${ids}) OR (to_type = ? AND to_id IN ${ids})`, type, accountKey, type, accountKey);
|
|
140
|
-
for (const [table, pointer] of [
|
|
141
|
-
["taggings", "taggable"],
|
|
142
|
-
["aliases", "aliasable"],
|
|
143
|
-
["attachments", "attachable"],
|
|
144
|
-
["link_reviews", "linkable"],
|
|
145
|
-
["entity_link_events", "linkable"],
|
|
146
|
-
])
|
|
147
|
-
run(`DELETE FROM ${table} WHERE ${pointer}_type = ? AND ${pointer}_id IN ${ids}`, type, accountKey);
|
|
148
|
-
run(`DELETE FROM pipeline_stage_changes WHERE item_type = ? AND item_id IN ${ids}`, type, accountKey);
|
|
149
|
-
}
|
|
139
|
+
new ErasePlan(database)
|
|
140
|
+
.pointers("deal", dealsOf.slice(1, -1), [accountKey])
|
|
141
|
+
.pointers("lead", leadsOf.slice(1, -1), [accountKey])
|
|
142
|
+
.run();
|
|
150
143
|
run(`DELETE FROM pipeline_stage_changes WHERE pipeline_id IN ${pipelinesOf}`, accountKey);
|
|
151
144
|
for (const table of ["leads", "orders", "contracts"])
|
|
152
145
|
run(`UPDATE ${table} SET deal_id = NULL WHERE deal_id IN ${dealsOf}`, accountKey);
|
|
@@ -3,10 +3,13 @@ import { pointerPairs } from "./entity-types.js";
|
|
|
3
3
|
const AUTHORS = new Set(["author", "confirmed_by", "decided_by", "proposed_by", "actor", "closed_by"]);
|
|
4
4
|
/** A link is about both ends: one that loses an end means nothing, so it goes. */
|
|
5
5
|
const LINK_ROWS = new Set(["links", "mentions", "task_assignments"]);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.
|
|
6
|
+
/** A row's own history: it goes before the row, and never keeps the row alive. */
|
|
7
|
+
const HISTORY = new Set(["note_revisions"]);
|
|
8
|
+
const childrenOf = (database, table) => database
|
|
9
|
+
.prepare(`SELECT m.name AS child, f."from" AS col, coalesce(f."to", 'id') AS parent FROM sqlite_master m
|
|
10
|
+
JOIN pragma_foreign_key_list(m.name) f WHERE m.type = 'table' AND f."table" = ?`)
|
|
11
|
+
.all(table)
|
|
12
|
+
.map((row) => ({ child: String(row.child), col: String(row.col), parent: String(row.parent) }));
|
|
10
13
|
const nullable = (database, table, column) => Number(database.prepare(`SELECT "notnull" AS n FROM pragma_table_info('${table}') WHERE name = ?`).get(column)?.n) ===
|
|
11
14
|
0;
|
|
12
15
|
export const count = (database, sql, ...params) => Number(database.prepare(`SELECT count(*) AS n FROM ${sql}`).get(...params)?.n);
|
|
@@ -32,7 +35,7 @@ export class ErasePlan {
|
|
|
32
35
|
continue;
|
|
33
36
|
const key = `${table}.${pointer}`;
|
|
34
37
|
if (LINK_ROWS.has(table) || !nullable(this.database, table, `${pointer}_id`)) {
|
|
35
|
-
if (!LINK_ROWS.has(table) && (AUTHORS.has(pointer) ||
|
|
38
|
+
if (!LINK_ROWS.has(table) && (AUTHORS.has(pointer) || !this.#history(table, where, params))) {
|
|
36
39
|
this.blocked.push(`${n} ${table} (${pointer})`);
|
|
37
40
|
continue;
|
|
38
41
|
}
|
|
@@ -67,6 +70,25 @@ export class ErasePlan {
|
|
|
67
70
|
for (const step of this.#steps)
|
|
68
71
|
step();
|
|
69
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Whether the rows `where` picks in `table` can go: rows of other tables that hang on them must be their history,
|
|
75
|
+
* which then goes first. Another table's row, such as an invoice under a contract, keeps them.
|
|
76
|
+
*/
|
|
77
|
+
#history(table, where, params) {
|
|
78
|
+
const steps = [];
|
|
79
|
+
for (const { child, col, parent } of childrenOf(this.database, table)) {
|
|
80
|
+
const hanging = `"${col}" IN (SELECT "${parent}" FROM "${table}" WHERE ${where})`;
|
|
81
|
+
const n = count(this.database, `"${child}" WHERE ${hanging}`, ...params);
|
|
82
|
+
if (n === 0)
|
|
83
|
+
continue;
|
|
84
|
+
if (!HISTORY.has(child))
|
|
85
|
+
return false;
|
|
86
|
+
steps.push([`${child}.${col}`, n, `DELETE FROM "${child}" WHERE ${hanging}`]);
|
|
87
|
+
}
|
|
88
|
+
for (const [key, n, sql] of steps)
|
|
89
|
+
this.#add(this.deleted, key, n, sql, params);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
70
92
|
#add(into, key, n, sql, params) {
|
|
71
93
|
into[key] = (into[key] ?? 0) + n;
|
|
72
94
|
this.#steps.push(() => this.database.prepare(sql).run(...params));
|
|
@@ -15,7 +15,8 @@ export interface OrganizationErasure {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Deletes an organization and what memo knows of it alone: the tags, links, aliases and mentions that name it, and
|
|
18
|
-
* which identities it held. A deal, lead, project, account
|
|
18
|
+
* which identities it held, and the owner's notes about it. A deal, lead, project, account or fact that names it stays
|
|
19
|
+
* and loses the name.
|
|
19
20
|
* Refused for one of the owner's own companies, and while an invoice, order, subscription or a row it wrote cannot
|
|
20
21
|
* be without it. `apply: false` answers the same without changing anything.
|
|
21
22
|
*/
|
|
@@ -18,7 +18,8 @@ const organizationOf = (database, ref) => {
|
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
20
|
* Deletes an organization and what memo knows of it alone: the tags, links, aliases and mentions that name it, and
|
|
21
|
-
* which identities it held. A deal, lead, project, account
|
|
21
|
+
* which identities it held, and the owner's notes about it. A deal, lead, project, account or fact that names it stays
|
|
22
|
+
* and loses the name.
|
|
22
23
|
* Refused for one of the owner's own companies, and while an invoice, order, subscription or a row it wrote cannot
|
|
23
24
|
* be without it. `apply: false` answers the same without changing anything.
|
|
24
25
|
*/
|
|
@@ -6,6 +6,8 @@ export interface PersonErasure {
|
|
|
6
6
|
name: string | null;
|
|
7
7
|
/** `false`: what `erase` would do, nothing changed. */
|
|
8
8
|
erased: boolean;
|
|
9
|
+
/** People merged into this one earlier: the same person, so they go too. */
|
|
10
|
+
merged: string[];
|
|
9
11
|
/** Identities that go with the person. */
|
|
10
12
|
identities: string[];
|
|
11
13
|
/**
|
|
@@ -23,7 +25,8 @@ export interface PersonErasure {
|
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Deletes a person and what memo knows of them alone: their identities, the tags, links, aliases and mentions that
|
|
26
|
-
* name them, their involvements
|
|
28
|
+
* name them, their involvements, the owner's notes about them, and the people merged into them earlier. A fact, a
|
|
29
|
+
* record or a task that names them stays and loses the name. A
|
|
27
30
|
* message, mail or meeting is the source's: its sender stays as an identity with no person. Refused for the owner,
|
|
28
31
|
* and while an invoice, order, subscription or a row they wrote cannot be without them. `apply: false` answers the
|
|
29
32
|
* same without changing anything.
|
|
@@ -33,7 +36,7 @@ export declare const erasePerson: (context: StoreContext, uid: string, by: Decid
|
|
|
33
36
|
export declare const importedPeople: (database: CacheDatabase, accountKey: number) => number[];
|
|
34
37
|
/**
|
|
35
38
|
* After a purge, the people only its records made go too: nothing else names them, and no message, mail or meeting
|
|
36
|
-
* names their identities; their involvements are derived and go with them. One the owner tagged, linked
|
|
37
|
-
*
|
|
39
|
+
* names their identities; their involvements are derived and go with them. One the owner tagged, linked, gave a task
|
|
40
|
+
* to or merged with another person stays: a merge says the owner knows them from somewhere else too.
|
|
38
41
|
*/
|
|
39
42
|
export declare const eraseImportedPeople: (context: StoreContext, people: readonly number[]) => void;
|
|
@@ -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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
70
|
-
|
|
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
|
|
75
|
-
.run(
|
|
76
|
-
database
|
|
77
|
-
|
|
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(
|
|
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
|
|
96
|
-
*
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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.
|
|
3
|
+
"version": "0.733.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",
|