@wirecat/cli-core 0.696.0 → 0.697.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 (56) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/cli/bot/api-http.d.ts +1 -1
  3. package/dist/cli/bot/api-http.js +77 -5
  4. package/dist/cli/bot/api-input.d.ts +5 -0
  5. package/dist/cli/bot/api-input.js +55 -0
  6. package/dist/cli/bot/api.d.ts +2 -0
  7. package/dist/cli/bot/api.js +12 -3
  8. package/dist/cli/messenger/store-maintenance-command.js +3 -2
  9. package/dist/cli/service-api-manifest.js +7 -4
  10. package/dist/cli/service-api.js +6 -2
  11. package/dist/crm/manifest/manifest.d.ts +2 -0
  12. package/dist/crm/manifest/manifest.js +2 -1
  13. package/dist/crm/manifest/map.d.ts +2 -1
  14. package/dist/crm/manifest/map.js +2 -1
  15. package/dist/domain/tracker.d.ts +100 -0
  16. package/dist/domain/tracker.js +28 -0
  17. package/dist/errors/reasons.js +1 -0
  18. package/dist/manifest/index.d.ts +9 -5
  19. package/dist/manifest/index.js +18 -7
  20. package/dist/store/exports.d.ts +1 -0
  21. package/dist/store/exports.js +1 -0
  22. package/dist/store/recover.js +2 -0
  23. package/dist/store/sqlite/account-purge.js +1 -0
  24. package/dist/store/sqlite/crm-files.d.ts +3 -0
  25. package/dist/store/sqlite/crm-files.js +2 -2
  26. package/dist/store/sqlite/manifest.js +2 -0
  27. package/dist/store/sqlite/migrations.generated.js +17 -0
  28. package/dist/store/sqlite/schema.d.ts +252 -0
  29. package/dist/store/sqlite/schema.js +28 -0
  30. package/dist/store/sqlite/tracker.d.ts +82 -0
  31. package/dist/store/sqlite/tracker.js +210 -0
  32. package/dist/store/store.d.ts +3 -0
  33. package/dist/store/store.js +5 -0
  34. package/dist/tracker/cli/index.d.ts +24 -0
  35. package/dist/tracker/cli/index.js +279 -0
  36. package/dist/tracker/index.d.ts +8 -0
  37. package/dist/tracker/index.js +7 -0
  38. package/dist/tracker/manifest/manifest.d.ts +76 -0
  39. package/dist/tracker/manifest/manifest.js +139 -0
  40. package/dist/tracker/manifest/map.d.ts +10 -0
  41. package/dist/tracker/manifest/map.js +86 -0
  42. package/dist/tracker/manifest/source.d.ts +18 -0
  43. package/dist/tracker/manifest/source.js +174 -0
  44. package/dist/tracker/source.d.ts +55 -0
  45. package/dist/tracker/source.js +1 -0
  46. package/dist/tracker/sync.d.ts +60 -0
  47. package/dist/tracker/sync.js +254 -0
  48. package/dist/tracker/tasks.d.ts +18 -0
  49. package/dist/tracker/tasks.js +29 -0
  50. package/dist/tracker/testing/index.d.ts +2 -0
  51. package/dist/tracker/testing/index.js +2 -0
  52. package/dist/tracker/testing/source-contract.d.ts +46 -0
  53. package/dist/tracker/testing/source-contract.js +246 -0
  54. package/dist/tracker/testing/source.d.ts +31 -0
  55. package/dist/tracker/testing/source.js +141 -0
  56. package/package.json +12 -4
@@ -0,0 +1,141 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ const OVERLAP_MS = 10 * 60_000;
3
+ /**
4
+ * A tracker in memory, read the way a GraphQL tracker is: changes by `updatedAt` from the cursor less an overlap, pages
5
+ * by offset, archived rows listed with their mark, deletions only by their absence from `ids()`. One call reads one
6
+ * page, so it never spends from the run's budget itself.
7
+ */
8
+ export const fakeTrackerSource = (options) => {
9
+ let tick = 0;
10
+ const clock = options.clock ?? (() => Date.UTC(2026, 10, 17) + tick++ * 1000);
11
+ const rows = options.rows;
12
+ const size = options.pageSize ?? 2;
13
+ const listOf = (kind) => (rows[kind] ?? []);
14
+ const find = (kind, externalId) => {
15
+ const found = listOf(kind).find((one) => one.externalId === externalId);
16
+ if (!found)
17
+ throw new Error(`the fake tracker has no ${kind} ${externalId}`);
18
+ return found;
19
+ };
20
+ const make = (skew) => ({
21
+ provider: options.provider ?? "fake-tracker",
22
+ traits: { kinds: Object.keys(rows).filter((kind) => listOf(kind).length > 0) },
23
+ async changes(kind, cursor, page, _context) {
24
+ const since = cursor === null ? null : Date.parse(cursor);
25
+ if (since !== null && Number.isNaN(since))
26
+ return { reset: true };
27
+ const [offsetText, startedText] = (page ?? "").split("@");
28
+ const offset = page === undefined ? 0 : Number(offsetText);
29
+ const started = page === undefined ? clock() + skew : Number(startedText);
30
+ if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(started))
31
+ throw new CliError("validation_error", `not a page of the fake tracker: ${page}`);
32
+ const listed = listOf(kind)
33
+ .filter((one) => since === null || (one.updatedAt ?? 0) >= since - OVERLAP_MS)
34
+ .sort((a, b) => (a.updatedAt ?? 0) - (b.updatedAt ?? 0) || a.externalId.localeCompare(b.externalId));
35
+ const items = listed.slice(offset, offset + size).map((one) => ({ ...one }));
36
+ const next = offset + size;
37
+ return next < listed.length
38
+ ? { items, hasMore: true, nextCursor: `${next}@${started}` }
39
+ : { items, hasMore: false, cursor: new Date(started).toISOString() };
40
+ },
41
+ async ids(kind, page, _context) {
42
+ const offset = page === undefined ? 0 : Number(page);
43
+ const all = listOf(kind).map((one) => one.externalId);
44
+ const items = all.slice(offset, offset + size);
45
+ return offset + size < all.length
46
+ ? { items, hasMore: true, nextCursor: String(offset + size) }
47
+ : { items, hasMore: false };
48
+ },
49
+ touch(kind, externalId) {
50
+ find(kind, externalId).updatedAt = clock();
51
+ },
52
+ archive(kind, externalId) {
53
+ const found = find(kind, externalId);
54
+ found.archivedAt = clock();
55
+ found.updatedAt = found.archivedAt;
56
+ },
57
+ remove(kind, externalId) {
58
+ const list = rows[kind];
59
+ const at = list?.findIndex((one) => one.externalId === externalId) ?? -1;
60
+ if (at < 0)
61
+ throw new Error(`the fake tracker has no ${kind} ${externalId}`);
62
+ list?.splice(at, 1);
63
+ },
64
+ skewed: (ms) => make(ms),
65
+ });
66
+ return make(options.skew ?? 0);
67
+ };
68
+ const T0 = Date.UTC(2026, 10, 1);
69
+ /** A small Linear-like workspace: one team, two users, the six state types, a label, a project, three issues. */
70
+ export const exampleTrackerRows = () => ({
71
+ team: [{ externalId: "team-1", key: "ENG", name: "Engineering", updatedAt: T0 }],
72
+ user: [
73
+ { externalId: "user-1", name: "Ada Owner", email: "ada@example.com", active: true, updatedAt: T0 },
74
+ { externalId: "user-2", name: "Bob Builder", email: "bob@example.com", active: true, updatedAt: T0 + 1 },
75
+ ],
76
+ state: [
77
+ { externalId: "state-triage", name: "Triage", type: "triage", team: "team-1", position: 0, updatedAt: T0 },
78
+ { externalId: "state-backlog", name: "Backlog", type: "backlog", team: "team-1", position: 1, updatedAt: T0 },
79
+ { externalId: "state-todo", name: "Todo", type: "unstarted", team: "team-1", position: 2, updatedAt: T0 },
80
+ { externalId: "state-doing", name: "In Progress", type: "started", team: "team-1", position: 3, updatedAt: T0 },
81
+ { externalId: "state-done", name: "Done", type: "completed", team: "team-1", position: 4, updatedAt: T0 },
82
+ { externalId: "state-gone", name: "Canceled", type: "canceled", team: "team-1", position: 5, updatedAt: T0 },
83
+ ],
84
+ label: [{ externalId: "label-bug", name: "Bug", team: "team-1", updatedAt: T0 }],
85
+ project: [
86
+ {
87
+ externalId: "project-1",
88
+ name: "Billing revamp",
89
+ description: "Move invoices to the new provider",
90
+ status: "started",
91
+ lead: "user-1",
92
+ teams: ["team-1"],
93
+ updatedAt: T0,
94
+ },
95
+ ],
96
+ issue: [
97
+ {
98
+ externalId: "issue-1",
99
+ key: "ENG-1",
100
+ title: "Invoices fail for EUR accounts",
101
+ description: "The provider refuses the currency code",
102
+ state: "state-doing",
103
+ team: "team-1",
104
+ project: "project-1",
105
+ assignee: "user-1",
106
+ labels: ["label-bug"],
107
+ priority: 1,
108
+ createdAt: T0,
109
+ updatedAt: T0 + 10,
110
+ },
111
+ {
112
+ externalId: "issue-2",
113
+ key: "ENG-2",
114
+ title: "Write the migration guide",
115
+ state: "state-todo",
116
+ team: "team-1",
117
+ project: "project-1",
118
+ assignee: "user-2",
119
+ labels: [],
120
+ priority: 3,
121
+ createdAt: T0,
122
+ updatedAt: T0 + 20,
123
+ },
124
+ {
125
+ externalId: "issue-3",
126
+ key: "ENG-3",
127
+ title: "Old spike",
128
+ state: "state-done",
129
+ team: "team-1",
130
+ assignee: null,
131
+ labels: [],
132
+ priority: 0,
133
+ createdAt: T0,
134
+ updatedAt: T0 + 30,
135
+ completedAt: T0 + 30,
136
+ },
137
+ ],
138
+ comment: [
139
+ { externalId: "comment-1", issue: "issue-1", body: "Seen on three accounts", author: "user-2", updatedAt: T0 + 11 },
140
+ ],
141
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.696.0",
3
+ "version": "0.697.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",
@@ -15,7 +15,7 @@
15
15
  "type": "module",
16
16
  "wirecat": {
17
17
  "store": {
18
- "speaks": 69,
18
+ "speaks": 70,
19
19
  "minCompatible": 56
20
20
  }
21
21
  },
@@ -159,6 +159,14 @@
159
159
  "types": "./dist/crm/testing/index.d.ts",
160
160
  "default": "./dist/crm/testing/index.js"
161
161
  },
162
+ "./tracker": {
163
+ "types": "./dist/tracker/index.d.ts",
164
+ "default": "./dist/tracker/index.js"
165
+ },
166
+ "./tracker/testing": {
167
+ "types": "./dist/tracker/testing/index.d.ts",
168
+ "default": "./dist/tracker/testing/index.js"
169
+ },
162
170
  "./mail": {
163
171
  "types": "./dist/mail/index.d.ts",
164
172
  "default": "./dist/mail/index.js"
@@ -305,7 +313,7 @@
305
313
  "@types/pngjs": "6.0.5",
306
314
  "@types/ssh2": "1.15.5",
307
315
  "@vitest/coverage-v8": "^5.0.5",
308
- "@wirecat/cli-base": "0.112.0",
316
+ "@wirecat/cli-base": "0.115.0",
309
317
  "@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
310
318
  "ajv": "8.17.1",
311
319
  "commander": "15.0.0",
@@ -329,7 +337,7 @@
329
337
  },
330
338
  "peerDependencies": {
331
339
  "@napi-rs/canvas": ">=0.1.69 <2",
332
- "@wirecat/cli-base": ">=0.112.0 <1.0.0",
340
+ "@wirecat/cli-base": ">=0.115.0 <1.0.0",
333
341
  "commander": ">=15",
334
342
  "mysql2": "^3.24.6",
335
343
  "pg": "^8.23.1",