@wirecat/cli-core 0.657.0 → 0.658.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 +14 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/calendar/index.d.ts +1 -1
- package/dist/calendar/index.js +1 -1
- package/dist/calendar/reads.d.ts +1 -0
- package/dist/calendar/reads.js +1 -1
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/listings.d.ts +46 -0
- package/dist/cli/listings.js +188 -0
- package/dist/cli/messenger/serve-relay.d.ts +1 -1
- package/dist/entities/listings.d.ts +514 -0
- package/dist/entities/listings.js +154 -0
- package/dist/errors/reasons.js +4 -0
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/listings.d.ts +74 -0
- package/dist/services/listings.js +285 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.js +2 -0
- package/dist/store/sqlite/calendar-events.d.ts +10 -0
- package/dist/store/sqlite/calendar-events.js +18 -8
- package/dist/store/sqlite/document-listing.d.ts +99 -0
- package/dist/store/sqlite/document-listing.js +292 -0
- package/dist/store/sqlite/files.d.ts +2 -0
- package/dist/store/sqlite/files.js +7 -3
- package/dist/store/sqlite/meeting-listing.d.ts +108 -0
- package/dist/store/sqlite/meeting-listing.js +431 -0
- package/dist/store/store.d.ts +4 -0
- package/dist/store/store.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { formatMeetingReference, joinKeyOf, MEETING_FINDINGS_KIND, parseMeetingReference, } from "../../meetings/index.js";
|
|
3
|
+
import { fold } from "../normalize.js";
|
|
4
|
+
import { eventWindow } from "./calendar-events.js";
|
|
5
|
+
import { COUNTERPART_ROLE, linkKind } from "./link-kinds.js";
|
|
6
|
+
import { samePersons } from "./merged-persons.js";
|
|
7
|
+
import { read } from "./transaction.js";
|
|
8
|
+
export const MEETING_ROW_KINDS = ["meeting", "call", "event"];
|
|
9
|
+
const DAY = 86_400_000;
|
|
10
|
+
/**
|
|
11
|
+
* The calendar event a meeting joins on the same room and time: a live, uncancelled copy whose `join_key` is the
|
|
12
|
+
* meeting's exactly (an empty key names no room) and whose event overlaps it. The nearest start wins.
|
|
13
|
+
*/
|
|
14
|
+
const JOINED = `(SELECT ce.event_id FROM calendar_entries ce JOIN events je ON je.id = ce.event_id
|
|
15
|
+
WHERE m.join_key <> '' AND ce.join_key = m.join_key AND ce.deleted_at IS NULL AND ce.status <> 'cancelled'
|
|
16
|
+
AND je.deleted_at IS NULL AND je.starts_at < coalesce(m.ended_at, m.started_at + 1)
|
|
17
|
+
AND coalesce(je.ends_at, je.starts_at + 1) > m.started_at
|
|
18
|
+
ORDER BY abs(je.starts_at - m.started_at), je.id LIMIT 1)`;
|
|
19
|
+
/**
|
|
20
|
+
* Each meeting's row: the event it is linked to, when a calendar holds it or the owner made it; else the event it
|
|
21
|
+
* shares a room and a time with; else the event made from it (`origin = 'auto'`); else its own row. A link the owner
|
|
22
|
+
* or a calendar made outranks a room match, which is only a guess.
|
|
23
|
+
*/
|
|
24
|
+
const HOME = `CASE
|
|
25
|
+
WHEN EXISTS (SELECT 1 FROM events he WHERE he.id = m.event_id AND he.deleted_at IS NULL
|
|
26
|
+
AND (he.origin <> 'auto' OR EXISTS (SELECT 1 FROM calendar_entries hc WHERE hc.event_id = he.id))) THEN m.event_id
|
|
27
|
+
ELSE coalesce(${JOINED}, (SELECT he.id FROM events he WHERE he.id = m.event_id AND he.deleted_at IS NULL)) END`;
|
|
28
|
+
export const accountOf = (row) => ({
|
|
29
|
+
id: Number(row.id),
|
|
30
|
+
provider: String(row.provider),
|
|
31
|
+
account: String(row.external_id),
|
|
32
|
+
name: row.name == null ? null : String(row.name),
|
|
33
|
+
});
|
|
34
|
+
const invalid = (message) => {
|
|
35
|
+
throw new CliError("validation_error", message);
|
|
36
|
+
};
|
|
37
|
+
const roomOf = (url) => (url == null ? null : (joinKeyOf(String(url)) ?? String(url)));
|
|
38
|
+
const str = (value) => (value == null ? null : String(value));
|
|
39
|
+
const num = (value) => (value == null ? null : Number(value));
|
|
40
|
+
const ids = (values) => JSON.stringify(values);
|
|
41
|
+
const rowsOf = (context, filter) => {
|
|
42
|
+
const { database } = context;
|
|
43
|
+
const window = eventWindow(database, filter);
|
|
44
|
+
const meetingWindow = [];
|
|
45
|
+
const meetingParams = [];
|
|
46
|
+
// Meetings a day either side are read for their homes: an event's own meeting may start a little outside it.
|
|
47
|
+
if (filter.from !== undefined) {
|
|
48
|
+
meetingWindow.push("m.started_at >= ?");
|
|
49
|
+
meetingParams.push(filter.from - DAY);
|
|
50
|
+
}
|
|
51
|
+
if (filter.to !== undefined) {
|
|
52
|
+
meetingWindow.push("m.started_at < ?");
|
|
53
|
+
meetingParams.push(filter.to + DAY);
|
|
54
|
+
}
|
|
55
|
+
const ownWindow = [];
|
|
56
|
+
const ownParams = [];
|
|
57
|
+
if (filter.from !== undefined) {
|
|
58
|
+
ownWindow.push("coalesce(m.ended_at, m.started_at + 1) > ?");
|
|
59
|
+
ownParams.push(filter.from);
|
|
60
|
+
}
|
|
61
|
+
if (filter.to !== undefined) {
|
|
62
|
+
ownWindow.push("m.started_at < ?");
|
|
63
|
+
ownParams.push(filter.to);
|
|
64
|
+
}
|
|
65
|
+
const and = (clauses) => clauses.map((clause) => ` AND ${clause}`).join("");
|
|
66
|
+
const groupWindow = [];
|
|
67
|
+
const groupParams = [];
|
|
68
|
+
if (filter.from !== undefined) {
|
|
69
|
+
groupWindow.push("ended_at > ?");
|
|
70
|
+
groupParams.push(filter.from);
|
|
71
|
+
}
|
|
72
|
+
if (filter.to !== undefined) {
|
|
73
|
+
groupWindow.push("started_at < ?");
|
|
74
|
+
groupParams.push(filter.to);
|
|
75
|
+
}
|
|
76
|
+
// An event whose meeting runs into the window is on it, though the event itself ended before the window starts.
|
|
77
|
+
// A UNION, not an OR, so the window still reads the events' time index.
|
|
78
|
+
const byMeeting = window.clauses.length === 0
|
|
79
|
+
? ""
|
|
80
|
+
: `UNION ALL
|
|
81
|
+
SELECT 'event', e.id, e.starts_at, e.ends_at, e.title FROM mg JOIN events e ON e.id = mg.event_id
|
|
82
|
+
WHERE e.deleted_at IS NULL AND NOT coalesce((${window.clauses.join(" AND ")}), 0)${and(groupWindow)}
|
|
83
|
+
`;
|
|
84
|
+
return {
|
|
85
|
+
sql: `WITH mh AS MATERIALIZED (
|
|
86
|
+
SELECT m.id AS meeting_id, m.account_id, m.started_at, coalesce(m.ended_at, m.started_at + 1) AS ended_at,
|
|
87
|
+
${HOME} AS event_id FROM meetings m
|
|
88
|
+
WHERE m.deleted_at IS NULL AND m.started_at IS NOT NULL${and(meetingWindow)}
|
|
89
|
+
),
|
|
90
|
+
mg AS MATERIALIZED (
|
|
91
|
+
SELECT event_id, json_group_array(meeting_id) AS meetings, min(started_at) AS started_at,
|
|
92
|
+
max(ended_at) AS ended_at
|
|
93
|
+
FROM mh WHERE event_id IS NOT NULL GROUP BY event_id
|
|
94
|
+
),
|
|
95
|
+
u AS (
|
|
96
|
+
SELECT 'event' AS type, e.id, e.starts_at AS starts_at, e.ends_at AS ends_at, e.title FROM events e
|
|
97
|
+
WHERE e.deleted_at IS NULL${and(window.clauses)}
|
|
98
|
+
AND (EXISTS (SELECT 1 FROM calendar_entries rc WHERE rc.event_id = e.id)
|
|
99
|
+
OR e.id IN (SELECT event_id FROM mg) OR e.origin = 'owner')
|
|
100
|
+
${byMeeting}UNION ALL
|
|
101
|
+
SELECT 'meeting', m.id, m.started_at, m.ended_at, m.title FROM meetings m JOIN mh ON mh.meeting_id = m.id
|
|
102
|
+
WHERE mh.event_id IS NULL${and(ownWindow)}
|
|
103
|
+
),
|
|
104
|
+
r AS (
|
|
105
|
+
SELECT u.*, CASE WHEN u.type = 'meeting' THEN json_array(u.id) ELSE coalesce(mg.meetings, '[]') END AS meetings
|
|
106
|
+
FROM u LEFT JOIN mg ON u.type = 'event' AND mg.event_id = u.id
|
|
107
|
+
)`,
|
|
108
|
+
params: [
|
|
109
|
+
...meetingParams,
|
|
110
|
+
...window.params,
|
|
111
|
+
...(window.clauses.length === 0 ? [] : [...window.params, ...groupParams]),
|
|
112
|
+
...ownParams,
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
const ROW_MEETINGS = "r.meetings";
|
|
117
|
+
const inRowMeetings = (condition) => `EXISTS (SELECT 1 FROM json_each(${ROW_MEETINGS}) rm WHERE ${condition.replaceAll("{m}", "rm.value")})`;
|
|
118
|
+
const PHONE_MEETING = "(SELECT a.provider FROM meetings km JOIN accounts a ON a.id = km.account_id WHERE km.id = {m}) = 'phone'";
|
|
119
|
+
const KIND = `(CASE
|
|
120
|
+
WHEN (r.type = 'event' AND EXISTS (SELECT 1 FROM calendar_entries kc WHERE kc.event_id = r.id
|
|
121
|
+
AND kc.deleted_at IS NULL AND kc.event_type = 'call')) OR ${inRowMeetings(PHONE_MEETING)} THEN 'call'
|
|
122
|
+
WHEN json_array_length(${ROW_MEETINGS}) > 0 THEN 'meeting'
|
|
123
|
+
ELSE 'event' END)`;
|
|
124
|
+
const filtersOf = (database, filter) => {
|
|
125
|
+
const clauses = [];
|
|
126
|
+
const params = [];
|
|
127
|
+
if (filter.kinds?.length) {
|
|
128
|
+
clauses.push(`${KIND} IN (SELECT value FROM json_each(?))`);
|
|
129
|
+
params.push(JSON.stringify(filter.kinds));
|
|
130
|
+
}
|
|
131
|
+
if (filter.accountIds !== undefined) {
|
|
132
|
+
if (filter.accountIds.length === 0)
|
|
133
|
+
invalid("accountIds names no account");
|
|
134
|
+
clauses.push(`((r.type = 'event' AND EXISTS (SELECT 1 FROM calendar_entries sc JOIN calendars s ON s.id = sc.calendar_id
|
|
135
|
+
WHERE sc.event_id = r.id AND s.account_id IN (SELECT value FROM json_each(?))))
|
|
136
|
+
OR ${inRowMeetings("(SELECT account_id FROM meetings WHERE id = {m}) IN (SELECT value FROM json_each(?))")})`);
|
|
137
|
+
params.push(ids(filter.accountIds), ids(filter.accountIds));
|
|
138
|
+
}
|
|
139
|
+
if (filter.personId !== undefined) {
|
|
140
|
+
const people = ids(samePersons(database, filter.personId));
|
|
141
|
+
clauses.push(`((r.type = 'event' AND (EXISTS (SELECT 1 FROM calendar_entries pc JOIN calendar_entry_participants pp
|
|
142
|
+
ON pp.entry_id = pc.id JOIN identity_links pl ON pl.identity_id = pp.identity_id
|
|
143
|
+
WHERE pc.event_id = r.id AND pc.deleted_at IS NULL AND pp.resource = 0 AND pl.person_id IN (SELECT value FROM json_each(?)))
|
|
144
|
+
OR EXISTS (SELECT 1 FROM links cl WHERE cl.from_type = 'event' AND cl.from_id = r.id AND cl.to_type = 'person'
|
|
145
|
+
AND cl.kind = ${linkKind("related-to")} AND cl.role = '${COUNTERPART_ROLE}'
|
|
146
|
+
AND cl.to_id IN (SELECT value FROM json_each(?)))))
|
|
147
|
+
OR ${inRowMeetings("EXISTS (SELECT 1 FROM meeting_participants mp JOIN identity_links ml ON ml.identity_id = mp.identity_id " +
|
|
148
|
+
"WHERE mp.meeting_id = {m} AND ml.person_id IN (SELECT value FROM json_each(?)))")})`);
|
|
149
|
+
params.push(people, people, people);
|
|
150
|
+
}
|
|
151
|
+
if (filter.hasTranscript !== undefined) {
|
|
152
|
+
clauses.push(`${filter.hasTranscript ? "" : "NOT "}${inRowMeetings("EXISTS (SELECT 1 FROM meeting_transcripts t WHERE t.meeting_id = {m} AND t.deleted_at IS NULL " +
|
|
153
|
+
"AND t.superseded_at IS NULL)")}`);
|
|
154
|
+
}
|
|
155
|
+
return { sql: clauses.length ? `WHERE ${clauses.join(" AND ")}` : "", params };
|
|
156
|
+
};
|
|
157
|
+
/** Every findings batch citing one of these meetings, with how many of its findings cite each. */
|
|
158
|
+
const citingBatches = (database, meetingIds) => {
|
|
159
|
+
if (meetingIds.size === 0)
|
|
160
|
+
return [];
|
|
161
|
+
// A batch is filed under the account of the meetings it reads, so only those accounts' batches are parsed.
|
|
162
|
+
const batches = database
|
|
163
|
+
.prepare(`SELECT id, status, payload FROM proposed_actions WHERE kind = ? AND account_id IN
|
|
164
|
+
(SELECT DISTINCT account_id FROM meetings WHERE id IN (SELECT value FROM json_each(?))) ORDER BY id DESC`)
|
|
165
|
+
.all(MEETING_FINDINGS_KIND, ids([...meetingIds]));
|
|
166
|
+
const found = [];
|
|
167
|
+
for (const batch of batches) {
|
|
168
|
+
let payload;
|
|
169
|
+
try {
|
|
170
|
+
payload = JSON.parse(String(batch.payload));
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const cited = new Map();
|
|
176
|
+
const pending = new Map();
|
|
177
|
+
const decided = new Set((payload.decided ?? []).map(({ id }) => id));
|
|
178
|
+
for (const finding of payload.findings ?? []) {
|
|
179
|
+
const meetings = new Set();
|
|
180
|
+
for (const evidence of finding.evidence ?? []) {
|
|
181
|
+
if (typeof evidence.reference !== "string")
|
|
182
|
+
continue;
|
|
183
|
+
try {
|
|
184
|
+
const meeting = parseMeetingReference(evidence.reference).meetingId;
|
|
185
|
+
if (meetingIds.has(meeting))
|
|
186
|
+
meetings.add(meeting);
|
|
187
|
+
}
|
|
188
|
+
catch { }
|
|
189
|
+
}
|
|
190
|
+
const open = batch.status === "proposed" && !decided.has(finding.id);
|
|
191
|
+
for (const meeting of meetings) {
|
|
192
|
+
cited.set(meeting, (cited.get(meeting) ?? 0) + 1);
|
|
193
|
+
if (open)
|
|
194
|
+
pending.set(meeting, (pending.get(meeting) ?? 0) + 1);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (cited.size > 0) {
|
|
198
|
+
const status = batch.status === "proposed" ? "proposed" : "reviewed";
|
|
199
|
+
found.push({ id: String(batch.id), status, cited, pending });
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return found;
|
|
203
|
+
};
|
|
204
|
+
/** Everything a page of rows shows, read once per page: a query per kind of fact, never one per row. */
|
|
205
|
+
const hydrate = (database, page) => {
|
|
206
|
+
const eventIds = page.filter(({ type }) => type === "event").map(({ id }) => id);
|
|
207
|
+
const meetingIds = [...new Set(page.flatMap(({ meetingIds }) => meetingIds))];
|
|
208
|
+
const events = new Map(database
|
|
209
|
+
.prepare("SELECT * FROM events WHERE id IN (SELECT value FROM json_each(?))")
|
|
210
|
+
.all(ids(eventIds))
|
|
211
|
+
.map((row) => [Number(row.id), row]));
|
|
212
|
+
const entries = database
|
|
213
|
+
.prepare(`SELECT ce.id, ce.event_id, ce.join_url, ce.timezone, ce.status, ce.deleted_at, ce.event_type,
|
|
214
|
+
c.title AS calendar, a.provider, a.external_id AS account FROM calendar_entries ce JOIN calendars c ON c.id = ce.calendar_id
|
|
215
|
+
JOIN accounts a ON a.id = c.account_id WHERE ce.event_id IN (SELECT value FROM json_each(?))
|
|
216
|
+
ORDER BY ce.deleted_at IS NOT NULL, ce.id`)
|
|
217
|
+
.all(ids(eventIds));
|
|
218
|
+
const meetings = new Map(database
|
|
219
|
+
.prepare(`SELECT m.*, a.provider, a.external_id AS account,
|
|
220
|
+
EXISTS (SELECT 1 FROM meeting_transcripts t WHERE t.meeting_id = m.id AND t.deleted_at IS NULL
|
|
221
|
+
AND t.superseded_at IS NULL) AS has_transcript,
|
|
222
|
+
EXISTS (SELECT 1 FROM meeting_summaries s WHERE s.meeting_id = m.id) AS has_summary,
|
|
223
|
+
(EXISTS (SELECT 1 FROM attachments ra WHERE ra.attachable_type = 'meeting' AND ra.attachable_id = m.id
|
|
224
|
+
AND (ra.kind IN ('audio', 'video') OR ra.mime LIKE 'audio/%' OR ra.mime LIKE 'video/%'))
|
|
225
|
+
OR EXISTS (SELECT 1 FROM links rl WHERE rl.from_type = 'meeting' AND rl.from_id = m.id
|
|
226
|
+
AND rl.kind = 'attached' AND rl.role = 'recording')) AS has_recording
|
|
227
|
+
FROM meetings m JOIN accounts a ON a.id = m.account_id WHERE m.id IN (SELECT value FROM json_each(?))`)
|
|
228
|
+
.all(ids(meetingIds))
|
|
229
|
+
.map((row) => [Number(row.id), row]));
|
|
230
|
+
const people = database
|
|
231
|
+
.prepare(`SELECT 'event' AS type, ce.event_id AS owner, p.name, p.email, p.organizer, l.person_id, pn.name AS person_name
|
|
232
|
+
FROM calendar_entries ce JOIN calendar_entry_participants p ON p.entry_id = ce.id
|
|
233
|
+
LEFT JOIN identity_links l ON l.identity_id = p.identity_id LEFT JOIN persons pn ON pn.id = l.person_id
|
|
234
|
+
WHERE ce.event_id IN (SELECT value FROM json_each(?)) AND ce.deleted_at IS NULL AND p.resource = 0
|
|
235
|
+
UNION ALL
|
|
236
|
+
SELECT 'meeting', mp.meeting_id, mp.display_name, mp.email, mp.role = 'host', l.person_id, pn.name
|
|
237
|
+
FROM meeting_participants mp LEFT JOIN identity_links l ON l.identity_id = mp.identity_id
|
|
238
|
+
LEFT JOIN persons pn ON pn.id = l.person_id
|
|
239
|
+
WHERE mp.meeting_id IN (SELECT value FROM json_each(?))
|
|
240
|
+
UNION ALL
|
|
241
|
+
SELECT 'event', cl.from_id, pe.name, NULL, 0, cl.to_id, pe.name FROM links cl JOIN persons pe ON pe.id = cl.to_id
|
|
242
|
+
WHERE cl.from_type = 'event' AND cl.from_id IN (SELECT value FROM json_each(?)) AND cl.to_type = 'person'
|
|
243
|
+
AND cl.kind = ${linkKind("related-to")} AND cl.role = '${COUNTERPART_ROLE}'`)
|
|
244
|
+
.all(ids(eventIds), ids(meetingIds), ids(eventIds));
|
|
245
|
+
const documents = database
|
|
246
|
+
.prepare(`SELECT 'meeting' AS type, l.from_id AS owner, l.to_id, l.role, d.title
|
|
247
|
+
FROM links l JOIN documents d ON d.id = l.to_id WHERE l.from_type = 'meeting' AND l.from_id IN (SELECT value FROM json_each(?)) AND l.kind = 'attached'
|
|
248
|
+
AND l.to_type = 'document' AND d.deleted_at IS NULL
|
|
249
|
+
UNION ALL
|
|
250
|
+
SELECT 'event', ce.event_id, l.to_id, l.role, d.title FROM links l JOIN calendar_entries ce ON ce.id = l.from_id
|
|
251
|
+
JOIN documents d ON d.id = l.to_id WHERE l.from_type = 'calendar_entry' AND l.kind = 'attached'
|
|
252
|
+
AND l.to_type = 'document' AND ce.event_id IN (SELECT value FROM json_each(?)) AND d.deleted_at IS NULL`)
|
|
253
|
+
.all(ids(meetingIds), ids(eventIds));
|
|
254
|
+
const batches = citingBatches(database, new Set(meetingIds));
|
|
255
|
+
return page.map(({ type, id, meetingIds: own }) => {
|
|
256
|
+
const countOf = (counts) => own.reduce((sum, meeting) => sum + (counts.get(meeting) ?? 0), 0);
|
|
257
|
+
const held = own.flatMap((one) => {
|
|
258
|
+
const row = meetings.get(one);
|
|
259
|
+
return row ? [row] : [];
|
|
260
|
+
});
|
|
261
|
+
held.sort((a, b) => Number(a.started_at) - Number(b.started_at) || Number(a.id) - Number(b.id));
|
|
262
|
+
const event = type === "event" ? events.get(id) : undefined;
|
|
263
|
+
const first = held[0];
|
|
264
|
+
const copies = type === "event" ? entries.filter((entry) => Number(entry.event_id) === id) : [];
|
|
265
|
+
const live = copies.filter((entry) => entry.deleted_at == null);
|
|
266
|
+
const sources = [
|
|
267
|
+
// A copy deleted in its calendar names the source only when no live copy is left.
|
|
268
|
+
...(live.length > 0 ? live : copies).map((entry) => ({
|
|
269
|
+
provider: String(entry.provider),
|
|
270
|
+
account: String(entry.account),
|
|
271
|
+
via: "calendar",
|
|
272
|
+
calendar: str(entry.calendar),
|
|
273
|
+
ref: `event:${id}`,
|
|
274
|
+
})),
|
|
275
|
+
...held.map((meeting) => ({
|
|
276
|
+
provider: String(meeting.provider),
|
|
277
|
+
account: String(meeting.account),
|
|
278
|
+
via: "meeting",
|
|
279
|
+
calendar: null,
|
|
280
|
+
ref: formatMeetingReference({
|
|
281
|
+
type: "meeting",
|
|
282
|
+
accountId: Number(meeting.account_id),
|
|
283
|
+
meetingId: Number(meeting.id),
|
|
284
|
+
}),
|
|
285
|
+
})),
|
|
286
|
+
].filter((source, index, all) => all.findIndex((other) => other.provider === source.provider &&
|
|
287
|
+
other.account === source.account &&
|
|
288
|
+
other.calendar === source.calendar &&
|
|
289
|
+
other.ref === source.ref) === index);
|
|
290
|
+
const participants = new Map();
|
|
291
|
+
for (const person of people) {
|
|
292
|
+
const mine = (person.type === "event" && type === "event" && Number(person.owner) === id) ||
|
|
293
|
+
(person.type === "meeting" && own.includes(Number(person.owner)));
|
|
294
|
+
if (!mine)
|
|
295
|
+
continue;
|
|
296
|
+
const ref = person.person_id == null ? null : `person:${person.person_id}`;
|
|
297
|
+
const email = str(person.email);
|
|
298
|
+
const key = ref ?? (email ? fold(email) : `name:${str(person.name) ?? ""}`);
|
|
299
|
+
const held = participants.get(key);
|
|
300
|
+
participants.set(key, {
|
|
301
|
+
name: held?.name ?? str(person.name),
|
|
302
|
+
email: held?.email ?? email,
|
|
303
|
+
person: ref === null ? null : { ref, name: str(person.person_name) },
|
|
304
|
+
organizer: (held?.organizer ?? false) || Number(person.organizer) === 1,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
const linked = new Map();
|
|
308
|
+
for (const document of documents) {
|
|
309
|
+
const mine = (document.type === "meeting" && own.includes(Number(document.owner))) ||
|
|
310
|
+
(document.type === "event" && type === "event" && Number(document.owner) === id);
|
|
311
|
+
if (mine && !linked.has(Number(document.to_id)))
|
|
312
|
+
linked.set(Number(document.to_id), {
|
|
313
|
+
ref: `document:${document.to_id}`,
|
|
314
|
+
title: str(document.title),
|
|
315
|
+
role: str(document.role),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
const startsAt = num(event ? event.starts_at : first?.started_at);
|
|
319
|
+
// The same order as KIND, which a filter by kind reads in SQL.
|
|
320
|
+
const kind = live.some((entry) => entry.event_type === "call") || held.some((meeting) => meeting.provider === "phone")
|
|
321
|
+
? "call"
|
|
322
|
+
: held.length > 0
|
|
323
|
+
? "meeting"
|
|
324
|
+
: "event";
|
|
325
|
+
return {
|
|
326
|
+
type,
|
|
327
|
+
id,
|
|
328
|
+
kind,
|
|
329
|
+
title: str(event?.title ?? first?.title),
|
|
330
|
+
startsAt,
|
|
331
|
+
endsAt: num(event ? event.ends_at : first?.ended_at),
|
|
332
|
+
allDay: Number(event?.all_day ?? 0) === 1,
|
|
333
|
+
timezone: str(event?.timezone ?? live.find((entry) => entry.timezone != null)?.timezone ?? first?.timezone),
|
|
334
|
+
links: [
|
|
335
|
+
...live.map((entry) => ({ source: `${entry.provider}:${entry.account}`, url: entry.join_url })),
|
|
336
|
+
...held.map((meeting) => ({ source: `${meeting.provider}:${meeting.account}`, url: meeting.join_url })),
|
|
337
|
+
].flatMap(({ source, url }, index, all) =>
|
|
338
|
+
// One room shared by a link with a passcode and one without is one link: the first, the calendar's.
|
|
339
|
+
url == null || all.findIndex((other) => roomOf(other.url) === roomOf(url)) !== index
|
|
340
|
+
? []
|
|
341
|
+
: [{ source, url: String(url) }]),
|
|
342
|
+
status: str(event?.status),
|
|
343
|
+
url: str(live.find((entry) => entry.join_url != null)?.join_url ?? held.find((m) => m.join_url != null)?.join_url),
|
|
344
|
+
meetings: held.map((meeting) => ({ id: Number(meeting.id), accountId: Number(meeting.account_id) })),
|
|
345
|
+
sources,
|
|
346
|
+
participants: [...participants.values()],
|
|
347
|
+
hasRecording: held.some((meeting) => Number(meeting.has_recording) === 1),
|
|
348
|
+
hasTranscript: held.some((meeting) => Number(meeting.has_transcript) === 1),
|
|
349
|
+
hasSummary: held.some((meeting) => Number(meeting.has_summary) === 1),
|
|
350
|
+
documents: [...linked.values()],
|
|
351
|
+
pendingFindings: batches.reduce((sum, { pending }) => sum + countOf(pending), 0),
|
|
352
|
+
findings: batches.flatMap(({ id, status, cited, pending }) => {
|
|
353
|
+
const findings = countOf(cited);
|
|
354
|
+
return findings > 0 ? [{ id, status, findings, pending: countOf(pending) }] : [];
|
|
355
|
+
}),
|
|
356
|
+
};
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
const pageOf = (row) => ({
|
|
360
|
+
type: row.type === "meeting" ? "meeting" : "event",
|
|
361
|
+
id: Number(row.id),
|
|
362
|
+
meetingIds: JSON.parse(String(row.meetings ?? "[]")).map(Number),
|
|
363
|
+
});
|
|
364
|
+
export const meetingListingOver = (context) => {
|
|
365
|
+
const { database } = context;
|
|
366
|
+
return {
|
|
367
|
+
meetingAccounts: async () => database
|
|
368
|
+
.prepare("SELECT id, provider, external_id, name FROM accounts WHERE id IN (SELECT account_id FROM calendars) " +
|
|
369
|
+
"OR id IN (SELECT account_id FROM meetings) ORDER BY provider, external_id")
|
|
370
|
+
.all()
|
|
371
|
+
.map(accountOf),
|
|
372
|
+
meetingRows: async (filter) => {
|
|
373
|
+
if (!Number.isInteger(filter.limit) || filter.limit < 1 || !Number.isInteger(filter.offset) || filter.offset < 0)
|
|
374
|
+
invalid("limit takes 1 or more and offset 0 or more");
|
|
375
|
+
return read(database, () => {
|
|
376
|
+
const rows = rowsOf(context, filter);
|
|
377
|
+
const filters = filtersOf(database, filter);
|
|
378
|
+
const order = filter.newest === false ? "r.starts_at, r.type, r.id" : "r.starts_at DESC, r.type DESC, r.id DESC";
|
|
379
|
+
const columns = `r.type, r.id, r.title, ${ROW_MEETINGS} AS meetings`;
|
|
380
|
+
const select = `${rows.sql} SELECT ${columns} FROM r ${filters.sql}`;
|
|
381
|
+
const words = (filter.titleWords ?? []).map(fold).filter((word) => word !== "");
|
|
382
|
+
if (words.length > 0) {
|
|
383
|
+
// SQLite's lower() folds ASCII only, so titles are compared folded here, as note search does.
|
|
384
|
+
const matched = database
|
|
385
|
+
.prepare(`${select} ORDER BY ${order}`)
|
|
386
|
+
.all(...rows.params, ...filters.params)
|
|
387
|
+
.filter((row) => {
|
|
388
|
+
const title = fold(str(row.title) ?? "");
|
|
389
|
+
return words.every((word) => title.includes(word));
|
|
390
|
+
});
|
|
391
|
+
return {
|
|
392
|
+
items: hydrate(database, matched.slice(filter.offset, filter.offset + filter.limit).map(pageOf)),
|
|
393
|
+
total: matched.length,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
const total = Number(database
|
|
397
|
+
.prepare(`${rows.sql} SELECT count(*) AS n FROM r ${filters.sql}`)
|
|
398
|
+
.get(...rows.params, ...filters.params)?.n);
|
|
399
|
+
const found = database
|
|
400
|
+
.prepare(`${select} ORDER BY ${order} LIMIT ? OFFSET ?`)
|
|
401
|
+
.all(...rows.params, ...filters.params, filter.limit, filter.offset);
|
|
402
|
+
return { items: hydrate(database, found.map(pageOf)), total };
|
|
403
|
+
});
|
|
404
|
+
},
|
|
405
|
+
meetingRow: async (target) => read(database, () => {
|
|
406
|
+
const meeting = "meeting" in target
|
|
407
|
+
? database
|
|
408
|
+
.prepare(`SELECT m.id, ${HOME} AS home FROM meetings m WHERE m.id = ? AND m.deleted_at IS NULL`)
|
|
409
|
+
.get(target.meeting)
|
|
410
|
+
: undefined;
|
|
411
|
+
if ("meeting" in target && !meeting)
|
|
412
|
+
return undefined;
|
|
413
|
+
const eventId = "event" in target ? target.event : num(meeting?.home);
|
|
414
|
+
if (eventId === null) {
|
|
415
|
+
const id = Number(meeting?.id);
|
|
416
|
+
return hydrate(database, [{ type: "meeting", id, meetingIds: [id] }])[0];
|
|
417
|
+
}
|
|
418
|
+
const event = database.prepare("SELECT * FROM events WHERE id = ? AND deleted_at IS NULL").get(eventId);
|
|
419
|
+
if (!event)
|
|
420
|
+
return undefined;
|
|
421
|
+
// Only a meeting linked to it or in one of its rooms can have it as home.
|
|
422
|
+
const meetingIds = database
|
|
423
|
+
.prepare(`SELECT m.id FROM meetings m WHERE m.deleted_at IS NULL AND m.started_at IS NOT NULL
|
|
424
|
+
AND (m.event_id = ? OR m.join_key IN (SELECT join_key FROM calendar_entries WHERE event_id = ?
|
|
425
|
+
AND join_key <> '')) AND ${HOME} = ? ORDER BY m.id`)
|
|
426
|
+
.all(eventId, eventId, eventId)
|
|
427
|
+
.map((row) => Number(row.id));
|
|
428
|
+
return hydrate(database, [{ type: "event", id: eventId, meetingIds }])[0];
|
|
429
|
+
}),
|
|
430
|
+
};
|
|
431
|
+
};
|
package/dist/store/store.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { type CatalogStore } from "./sqlite/catalog.js";
|
|
|
28
28
|
import { type CrmCopies } from "./sqlite/crm.js";
|
|
29
29
|
import { type DealsStore } from "./sqlite/deals.js";
|
|
30
30
|
import { type DecisionRequestStore } from "./sqlite/decision-requests.js";
|
|
31
|
+
import { type DocumentListing } from "./sqlite/document-listing.js";
|
|
31
32
|
import { type MailStore } from "./sqlite/emails.js";
|
|
32
33
|
import { type EnrichmentStore } from "./sqlite/enrichments.js";
|
|
33
34
|
import { type EventSearch } from "./sqlite/event-search.js";
|
|
@@ -36,6 +37,7 @@ import { type FilesStore } from "./sqlite/files.js";
|
|
|
36
37
|
import { type FinanceStore } from "./sqlite/finance.js";
|
|
37
38
|
import { type InvolvementStore } from "./sqlite/involvements.js";
|
|
38
39
|
import { type KnowledgeStore } from "./sqlite/knowledge.js";
|
|
40
|
+
import { type MeetingListing } from "./sqlite/meeting-listing.js";
|
|
39
41
|
import { type MeetingVectors } from "./sqlite/meeting-vectors.js";
|
|
40
42
|
import { type StoredMeetings } from "./sqlite/meetings.js";
|
|
41
43
|
import { type MemoriesStore } from "./sqlite/memories.js";
|
|
@@ -103,6 +105,8 @@ export interface MessageStore {
|
|
|
103
105
|
readonly catalog: CatalogStore;
|
|
104
106
|
/** Where each document is kept: its files, their folders and paths. */
|
|
105
107
|
readonly files: FilesStore;
|
|
108
|
+
/** Every document of every account, and every meeting, call and event as one row each: what a page lists. */
|
|
109
|
+
readonly listings: DocumentListing & MeetingListing;
|
|
106
110
|
/** Calendars and their entries, the source records of events: the `EventStore` a calendar CLI writes through. */
|
|
107
111
|
readonly calendar: EventStore & EventSearch;
|
|
108
112
|
/** Choices that hold until replaced, each with its evidence. */
|
package/dist/store/store.js
CHANGED
|
@@ -26,6 +26,7 @@ import { contextEvidenceOver, contextIndexOver, contextRecordsOver } from "./sql
|
|
|
26
26
|
import { crmCopiesOver } from "./sqlite/crm.js";
|
|
27
27
|
import { dealsStoreOver } from "./sqlite/deals.js";
|
|
28
28
|
import { decisionRequestStoreOver } from "./sqlite/decision-requests.js";
|
|
29
|
+
import { documentListingOver } from "./sqlite/document-listing.js";
|
|
29
30
|
import { mailStoreOver } from "./sqlite/emails.js";
|
|
30
31
|
import { enrichmentsOver } from "./sqlite/enrichments.js";
|
|
31
32
|
import { eventSearchOver } from "./sqlite/event-search.js";
|
|
@@ -38,6 +39,7 @@ import { knowledgeStoreOver } from "./sqlite/knowledge.js";
|
|
|
38
39
|
import { logPruner } from "./sqlite/log-pruning.js";
|
|
39
40
|
import { mailFindingsStoreOver } from "./sqlite/mail-findings.js";
|
|
40
41
|
import { meetingFindingsStoreOver } from "./sqlite/meeting-findings.js";
|
|
42
|
+
import { meetingListingOver } from "./sqlite/meeting-listing.js";
|
|
41
43
|
import { meetingVectorsOver } from "./sqlite/meeting-vectors.js";
|
|
42
44
|
import { meetingStoreOver } from "./sqlite/meetings.js";
|
|
43
45
|
import { memoriesStoreOver } from "./sqlite/memories.js";
|
|
@@ -120,6 +122,7 @@ const storeOver = (context) => {
|
|
|
120
122
|
const notes = once(() => ({ ...notesStoreOver(context), ...addedSourcesOver(context), ...noteSearchOver(context) }));
|
|
121
123
|
const catalog = once(() => catalogStoreOver(context));
|
|
122
124
|
const files = once(() => filesStoreOver(context));
|
|
125
|
+
const listings = once(() => ({ ...documentListingOver(context), ...meetingListingOver(context) }));
|
|
123
126
|
const calendar = once(() => ({ ...eventStoreOver(context), ...eventSearchOver(context) }));
|
|
124
127
|
const meetingFindings = once(() => meetingFindingsStoreOver(context));
|
|
125
128
|
const evidenceFindings = once(() => evidenceFindingsStoreOver(context));
|
|
@@ -231,6 +234,9 @@ const storeOver = (context) => {
|
|
|
231
234
|
get files() {
|
|
232
235
|
return files();
|
|
233
236
|
},
|
|
237
|
+
get listings() {
|
|
238
|
+
return listings();
|
|
239
|
+
},
|
|
234
240
|
get calendar() {
|
|
235
241
|
return calendar();
|
|
236
242
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.658.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",
|