@wirecat/cli-core 0.638.0 → 0.640.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 (47) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/domain/crm.d.ts +3 -0
  3. package/dist/domain/name-variants.d.ts +2 -0
  4. package/dist/domain/name-variants.js +107 -0
  5. package/dist/domain/person-kinds.d.ts +6 -3
  6. package/dist/domain/person-kinds.js +5 -2
  7. package/dist/entities/contact-activity.d.ts +3 -0
  8. package/dist/entities/contact-activity.js +3 -0
  9. package/dist/entities/contact-context.d.ts +6 -0
  10. package/dist/entities/index.d.ts +6 -0
  11. package/dist/errors/reasons.js +2 -1
  12. package/dist/resolve.d.ts +8 -0
  13. package/dist/resolve.js +48 -6
  14. package/dist/search/lucene/registry.js +17 -15
  15. package/dist/services/agenda.js +8 -1
  16. package/dist/services/message-resolution.d.ts +12 -0
  17. package/dist/services/message-resolution.js +42 -1
  18. package/dist/services/messages-search.js +29 -15
  19. package/dist/services/metadata.d.ts +1 -1
  20. package/dist/services/task-rules.js +1 -1
  21. package/dist/store/index.d.ts +2 -2
  22. package/dist/store/people.d.ts +10 -3
  23. package/dist/store/people.js +2 -1
  24. package/dist/store/sqlite/accounts.js +2 -0
  25. package/dist/store/sqlite/crm.js +5 -0
  26. package/dist/store/sqlite/hit-places.js +19 -6
  27. package/dist/store/sqlite/identities.js +21 -1
  28. package/dist/store/sqlite/knowledge.js +5 -2
  29. package/dist/store/sqlite/lucene-fields.d.ts +2 -1
  30. package/dist/store/sqlite/lucene-fields.js +76 -16
  31. package/dist/store/sqlite/lucene.js +8 -8
  32. package/dist/store/sqlite/note-search.js +9 -0
  33. package/dist/store/sqlite/people-list.js +14 -8
  34. package/dist/store/sqlite/person-doubts.d.ts +13 -3
  35. package/dist/store/sqlite/person-doubts.js +92 -48
  36. package/dist/store/sqlite/person-links.js +15 -2
  37. package/dist/store/sqlite/task-board.d.ts +4 -2
  38. package/dist/store/sqlite/task-board.js +5 -3
  39. package/dist/store/sqlite/task-stats.js +2 -2
  40. package/dist/store/sqlite/tasks.js +20 -3
  41. package/dist/store/sqlite/test-people.d.ts +24 -0
  42. package/dist/store/sqlite/test-people.js +92 -0
  43. package/dist/store/sqlite/work-tasks.d.ts +7 -3
  44. package/dist/store/sqlite/work-tasks.js +9 -7
  45. package/dist/store/types.d.ts +6 -0
  46. package/docs/search/recipes.json +3 -0
  47. package/package.json +1 -1
@@ -44,6 +44,10 @@ export interface TaskFields {
44
44
  /** The http or https page the task is about, such as an Avito ad; `null` clears it. */
45
45
  sourceUrl?: string | null;
46
46
  }
47
+ /** What `edit` takes: a task found in a message keeps a message kind until it moves into a project. */
48
+ export type TaskEdit = Omit<TaskFields, "type"> & {
49
+ type?: TaskType;
50
+ };
47
51
  export interface NewWorkTask extends Omit<TaskFields, "reason" | "project" | "type"> {
48
52
  /** `project:<id>` or the project's key. */
49
53
  project: string;
@@ -184,7 +188,7 @@ export interface TaskEvent {
184
188
  /** Tasks beyond the package's four message kinds, and the fields the package does not know, on any task. */
185
189
  export interface WorkTasks extends TaskRelationsStore {
186
190
  create(input: NewWorkTask, by: Author): Promise<TaskDetails>;
187
- edit(id: string, fields: TaskFields, by: Author, check?: RevisionCheck): Promise<EditedTask>;
191
+ edit(id: string, fields: TaskEdit, by: Author, check?: RevisionCheck): Promise<EditedTask>;
188
192
  assign(id: string, assignment: TaskAssignment, by: Author, check?: RevisionCheck): Promise<TaskDetails>;
189
193
  unassign(id: string, assignment: TaskAssignment, by: Author, check?: RevisionCheck): Promise<TaskDetails>;
190
194
  /**
@@ -216,7 +220,7 @@ export interface WorkTasks extends TaskRelationsStore {
216
220
  comment(id: string, text: string, by: Author): Promise<TaskComment>;
217
221
  /** Its comments, oldest first. */
218
222
  comments(id: string): Promise<TaskComment[]>;
219
- /** The owner's project tasks, every project at once, narrowed by a query over `PROJECT_TASK_FIELDS`. */
223
+ /** Every live task, the found ones too, narrowed by a query over `PROJECT_TASK_FIELDS`. */
220
224
  board(query: QueryAst | undefined, options: BoardOptions): Promise<{
221
225
  items: TaskDetails[];
222
226
  total: number;
@@ -249,7 +253,7 @@ export declare const checkRevision: (row: Row, expected: number | undefined) =>
249
253
  type WorkTaskOperations = Omit<WorkTasks, "create" | "assign"> & {
250
254
  create(input: NewWorkTask, by: Author): TaskDetails;
251
255
  assign(id: string, assignment: TaskAssignment, by: Author, check?: RevisionCheck): TaskDetails;
252
- editNow(id: string, fields: TaskFields, by: Author): TaskDetails;
256
+ editNow(id: string, fields: TaskEdit, by: Author): TaskDetails;
253
257
  };
254
258
  export declare const workTaskOperationsOver: (context: StoreContext) => WorkTaskOperations;
255
259
  export declare const workTasksOver: (context: StoreContext) => WorkTasks;
@@ -2,7 +2,7 @@ import { CliError } from "@wirecat/cli-base";
2
2
  import { timezoneOf } from "@wirecat/cli-base/query";
3
3
  import { externalIdOf, externalIdText, sourceUrlOf } from "../../domain/external-links.js";
4
4
  import { TASK_TYPES, WORK_TASK_TYPES } from "../../domain/knowledge.js";
5
- import { checkedScore, isClosedState, legacyPriority, PRIORITY_LABELS, priorityBand, priorityLabel, TASK_STATES, } from "../../tasks/index.js";
5
+ import { checkedScore, isClosedState, legacyPriority, PRIORITY_LABELS, priorityBand, priorityLabel, TASK_KINDS, TASK_STATES, } from "../../tasks/index.js";
6
6
  import { folded } from "./folded.js";
7
7
  import { authorActor } from "./memories.js";
8
8
  import { idsOf } from "./merged-persons.js";
@@ -173,6 +173,7 @@ export const workTaskOperationsOver = (context) => {
173
173
  const countOf = (where) => Number(database.prepare(`SELECT count(*) AS n FROM tasks t WHERE ${where.sql}`).get(...where.params)?.n ?? 0);
174
174
  const rowById = (id) => database.prepare("SELECT * FROM tasks WHERE id = ?").get(id);
175
175
  const details = (id) => detailsOf(rowById(id));
176
+ const inInbox = (project) => String(database.prepare("SELECT key FROM projects WHERE id = ?").get(project)?.key).length === INBOX_KEY_LENGTH;
176
177
  const onBoard = (task) => Boolean(database.prepare(`SELECT 1 FROM tasks t WHERE t.id = ? AND ${BOARD_SCOPE}`).get(task));
177
178
  /** The task takes the target's next number and key; the source's counter never goes back, so its old key stays unique. */
178
179
  const moveToProject = (task, before, target, actor, at, detach) => {
@@ -252,10 +253,6 @@ export const workTaskOperationsOver = (context) => {
252
253
  if (fields.status !== undefined) {
253
254
  if (!TASK_STATES.includes(fields.status))
254
255
  throw new CliError("validation_error", `a task's status is one of ${TASK_STATES.join(", ")}`);
255
- if ((fields.status === "todo" || fields.status === "in_progress") &&
256
- String(database.prepare("SELECT key FROM projects WHERE id = ?").get(Number(before.project_id))?.key).length ===
257
- INBOX_KEY_LENGTH)
258
- throw new CliError("validation_error", "a task from a message is open, done or dismissed; todo and in_progress are for a project task");
259
256
  const closed = isClosedState(fields.status);
260
257
  const reopened = !closed && isClosedState(String(before.status));
261
258
  if (before.status !== fields.status) {
@@ -297,8 +294,12 @@ export const workTaskOperationsOver = (context) => {
297
294
  if (fields.category !== undefined)
298
295
  change("category", fields.category, "category");
299
296
  if (fields.type !== undefined && fields.type !== before.type) {
300
- if (!WORK_TASK_TYPES.includes(fields.type) || !onBoard(task))
301
- throw new CliError("validation_error", `a project task's kind is one of ${WORK_TASK_TYPES.join(", ")}`);
297
+ // The task package reads a message kind back, so a task keeps one while it stays in its inbox.
298
+ const found = inInbox(fields.project === undefined ? Number(before.project_id) : projectOf(fields.project));
299
+ const kinds = found ? TASK_KINDS : WORK_TASK_TYPES;
300
+ const what = `a ${found ? "found" : "project"} task's kind is one of ${kinds.join(", ")}`;
301
+ if (!kinds.includes(fields.type) || !onBoard(task))
302
+ throw new CliError("validation_error", what);
302
303
  change("type", fields.type, "type");
303
304
  bump = true;
304
305
  }
@@ -578,6 +579,7 @@ export const workTaskOperationsOver = (context) => {
578
579
  .all(...where.params);
579
580
  };
580
581
  const project = grouped("project", "p.id, p.key, p.name", "JOIN projects p ON p.id = t.project_id", "p.id")
582
+ .filter((row) => String(row.key).length !== INBOX_KEY_LENGTH)
581
583
  .map((row) => ({
582
584
  value: String(row.key),
583
585
  ref: `project:${row.id}`,
@@ -36,6 +36,9 @@ export interface PersonFacts {
36
36
  email?: string | null;
37
37
  /** As the provider showed it, whole; only where it shows it to the owner. */
38
38
  phone?: string | null;
39
+ /** Every phone and address the source gives, as a CRM contact holds several; left out, the stored ones stay. */
40
+ phones?: string[];
41
+ emails?: string[];
39
42
  }
40
43
  /** One identity in one messenger, by the messenger's own id. `provider` is any string: `email` is one. */
41
44
  export interface IdentityRef {
@@ -57,6 +60,9 @@ export interface LinkedIdentity extends IdentityRef {
57
60
  /** The phone and address its source gave it, when it gave one. */
58
61
  phone?: string | null;
59
62
  email?: string | null;
63
+ /** Every phone and address its source gave, `phone` and `email` among them; empty when it gave none. */
64
+ phones?: string[];
65
+ emails?: string[];
60
66
  isBot: boolean | null;
61
67
  /** The accounts in this store that have seen it. */
62
68
  accounts: Id[];
@@ -88,6 +88,7 @@
88
88
  "fileTexts": [{ "chat": "7", "message": "105", "attachment": 1, "text": "Накладная № 17, оплата до 31 января" }],
89
89
  "recipes": [
90
90
  { "title": "Слово", "query": "invoice", "ids": ["101", "102", "105", "106"] },
91
+ { "title": "Слово по началу", "query": "invoi*", "ids": ["101", "102", "105", "106"] },
91
92
  { "title": "Другие формы слова", "query": "квартира", "ids": ["109"] },
92
93
  { "title": "Фраза в кавычках — тоже в любой форме", "query": "\"квартира\"", "ids": ["109"] },
93
94
  { "title": "Только точная форма", "query": "exact:квартира", "ids": [] },
@@ -98,8 +99,10 @@
98
99
  "ids": ["101", "102", "105", "106"]
99
100
  },
100
101
  { "title": "Чат по имени", "query": "chat:\"Work fixture\" AND invoice", "ids": ["101", "102", "105", "106"] },
102
+ { "title": "Чат по части названия", "query": "chat:*work* AND invoice", "ids": ["101", "102", "105", "106"] },
101
103
  { "title": "Диапазон дат", "query": "invoice date:[2026-01-20 TO 2026-01-22}", "ids": ["101", "102"] },
102
104
  { "title": "Все сообщения автора", "query": "from:\"Bob Synthetic\"", "ids": ["106", "107", "108"] },
105
+ { "title": "Автор по части имени", "query": "from:Bo*", "ids": ["106", "107", "108"] },
103
106
  { "title": "Начиная с даты", "query": "invoice date>=2026-01-21", "ids": ["102", "105", "106"] },
104
107
  { "title": "Личная переписка", "query": "passport kind:private", "ids": ["103"] },
105
108
  { "title": "Кандидат secret в Избранном", "query": "preset:secret kind:saved", "ids": ["104"] },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.638.0",
3
+ "version": "0.640.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",