@wirecat/cli-core 0.656.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 +22 -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/mail/meeting-notes.d.ts +9 -2
- package/dist/mail/meeting-notes.js +18 -5
- 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,292 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { normalizeTag } from "../../domain/tags.js";
|
|
3
|
+
import { PREFERRED_FILE, subtreeOf } from "./files.js";
|
|
4
|
+
import { accountOf } from "./meeting-listing.js";
|
|
5
|
+
import { idsOf } from "./merged-persons.js";
|
|
6
|
+
import { queryFilter } from "./query-filter.js";
|
|
7
|
+
import { canonicalTagNamed } from "./tags.js";
|
|
8
|
+
import { thingOf } from "./things.js";
|
|
9
|
+
import { read } from "./transaction.js";
|
|
10
|
+
/** What a document is to a person, from its MIME type and file name: the Documents page filters and shows by it. */
|
|
11
|
+
export const DOCUMENT_KINDS = [
|
|
12
|
+
"transcript",
|
|
13
|
+
"doc",
|
|
14
|
+
"sheet",
|
|
15
|
+
"slides",
|
|
16
|
+
"pdf",
|
|
17
|
+
"docx",
|
|
18
|
+
"xlsx",
|
|
19
|
+
"pptx",
|
|
20
|
+
"csv",
|
|
21
|
+
"md",
|
|
22
|
+
"txt",
|
|
23
|
+
"html",
|
|
24
|
+
"page",
|
|
25
|
+
"image",
|
|
26
|
+
"other",
|
|
27
|
+
];
|
|
28
|
+
const ext = "lower(coalesce(d.extension, ''))";
|
|
29
|
+
const mime = "coalesce(f.mime, d.mime, '')";
|
|
30
|
+
const among = (values) => `${ext} IN (${values.map((value) => `'${value}'`).join(", ")})`;
|
|
31
|
+
/** A meeting's transcript saved as a document (a Meet transcript Drive imported) is a transcript whatever its type. */
|
|
32
|
+
const TRANSCRIPT_LINK = "EXISTS (SELECT 1 FROM links tl WHERE tl.to_type = 'document' AND tl.to_id = d.id AND tl.from_type = 'meeting' " +
|
|
33
|
+
"AND tl.kind = 'attached' AND tl.role = 'transcript')";
|
|
34
|
+
const OFFICE = "application/vnd.openxmlformats-officedocument";
|
|
35
|
+
export const DOCUMENT_KIND_SQL = `CASE
|
|
36
|
+
WHEN ${among(["vtt", "srt"])} OR ${TRANSCRIPT_LINK} THEN 'transcript'
|
|
37
|
+
WHEN ${mime} = 'application/vnd.google-apps.document' THEN 'doc'
|
|
38
|
+
WHEN ${mime} = 'application/vnd.google-apps.spreadsheet' THEN 'sheet'
|
|
39
|
+
WHEN ${mime} = 'application/vnd.google-apps.presentation' THEN 'slides'
|
|
40
|
+
WHEN ${mime} = 'application/pdf' OR ${among(["pdf"])} THEN 'pdf'
|
|
41
|
+
WHEN ${among(["docx", "doc", "odt", "rtf", "epub"])} OR ${mime} LIKE '${OFFICE}.wordprocessingml%' THEN 'docx'
|
|
42
|
+
WHEN ${among(["xlsx", "xls", "ods"])} OR ${mime} LIKE '${OFFICE}.spreadsheetml%' THEN 'xlsx'
|
|
43
|
+
WHEN ${among(["pptx", "ppt", "odp"])} OR ${mime} LIKE '${OFFICE}.presentationml%' THEN 'pptx'
|
|
44
|
+
WHEN ${among(["csv", "tsv"])} OR ${mime} IN ('text/csv', 'text/tab-separated-values') THEN 'csv'
|
|
45
|
+
WHEN ${among(["md", "markdown"])} OR ${mime} = 'text/markdown' THEN 'md'
|
|
46
|
+
WHEN ${among(["txt", "text", "log"])} OR ${mime} = 'text/plain' THEN 'txt'
|
|
47
|
+
WHEN ${among(["html", "htm"])} OR ${mime} = 'text/html' THEN 'html'
|
|
48
|
+
WHEN ${mime} LIKE 'image/%' THEN 'image'
|
|
49
|
+
WHEN d.kind = 'page' THEN 'page'
|
|
50
|
+
WHEN d.kind = 'text' THEN 'txt'
|
|
51
|
+
ELSE 'other' END`;
|
|
52
|
+
const PREFERRED = "LEFT JOIN files f ON f.id = (SELECT f.id FROM files f WHERE f.document_id = d.id AND f.kind <> 'folder' " +
|
|
53
|
+
`ORDER BY ${PREFERRED_FILE} LIMIT 1)`;
|
|
54
|
+
/** Documents a list shows: not deleted, not a folder, and still in its source's catalog. */
|
|
55
|
+
const LISTED = "d.deleted_at IS NULL AND d.kind <> 'folder' AND coalesce(json_extract(d.metadata, '$.catalog.active'), 1) = 1";
|
|
56
|
+
const MODIFIED = "coalesce(f.external_updated_at, d.external_updated_at, d.updated_at)";
|
|
57
|
+
/** A document's place: its preferred file's path, else where a folder import put it. */
|
|
58
|
+
const PATH = "coalesce(f.path, CASE WHEN d.storage = 'local' THEN d.external_id END)";
|
|
59
|
+
// lower() folds ASCII only; the files' own paths are folded in full when stored.
|
|
60
|
+
const PATH_FOLDED = "coalesce(f.path_folded, CASE WHEN d.storage = 'local' THEN lower(d.external_id) END)";
|
|
61
|
+
const COLUMNS = `d.id, d.account_id, a.provider, a.external_id AS account, a.name AS account_name, d.title, d.file_name,
|
|
62
|
+
${DOCUMENT_KIND_SQL} AS kind, coalesce(f.mime, d.mime) AS mime, coalesce(f.size, d.size) AS size,
|
|
63
|
+
coalesce(f.url, d.url) AS url, d.local_path, ${PATH} AS path, ${MODIFIED} AS modified_at, d.updated_at,
|
|
64
|
+
d.body IS NOT NULL AS has_text`;
|
|
65
|
+
const str = (value) => (value == null ? null : String(value));
|
|
66
|
+
const num = (value) => (value == null ? null : Number(value));
|
|
67
|
+
const folderOf = (path) => {
|
|
68
|
+
if (path === null)
|
|
69
|
+
return null;
|
|
70
|
+
const slash = path.lastIndexOf("/");
|
|
71
|
+
return slash <= 0 ? null : path.slice(0, slash);
|
|
72
|
+
};
|
|
73
|
+
const rowOf = (row) => {
|
|
74
|
+
const path = str(row.path);
|
|
75
|
+
return {
|
|
76
|
+
id: Number(row.id),
|
|
77
|
+
accountId: Number(row.account_id),
|
|
78
|
+
provider: String(row.provider),
|
|
79
|
+
account: String(row.account),
|
|
80
|
+
accountName: str(row.account_name),
|
|
81
|
+
title: str(row.title),
|
|
82
|
+
fileName: str(row.file_name),
|
|
83
|
+
kind: String(row.kind),
|
|
84
|
+
mime: str(row.mime),
|
|
85
|
+
size: num(row.size),
|
|
86
|
+
url: str(row.url),
|
|
87
|
+
localPath: str(row.local_path),
|
|
88
|
+
path,
|
|
89
|
+
folder: folderOf(path),
|
|
90
|
+
modifiedAt: num(row.modified_at),
|
|
91
|
+
storedAt: Number(row.updated_at),
|
|
92
|
+
hasText: Number(row.has_text) === 1,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const invalid = (message) => {
|
|
96
|
+
throw new CliError("validation_error", message);
|
|
97
|
+
};
|
|
98
|
+
/** The list's fields as the store answers them; `text` is searched before, and arrives as `ids`. */
|
|
99
|
+
const columns = (context) => {
|
|
100
|
+
const { database } = context;
|
|
101
|
+
return {
|
|
102
|
+
kind: { type: "enum", sql: DOCUMENT_KIND_SQL },
|
|
103
|
+
source_modified_at: { type: "time", sql: MODIFIED },
|
|
104
|
+
has_text: { type: "bool", sql: "(d.body IS NOT NULL)" },
|
|
105
|
+
folder: {
|
|
106
|
+
where: (node) => {
|
|
107
|
+
const [low, high] = subtreeOf(node.value.replace(/^\/+/u, ""));
|
|
108
|
+
return { sql: `(${PATH_FOLDED} >= ? AND ${PATH_FOLDED} < ?)`, params: [low, high], known: true };
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
tag: {
|
|
112
|
+
where: (node) => ({
|
|
113
|
+
sql: "EXISTS (SELECT 1 FROM taggings g JOIN resolved_tags t ON t.id = g.tag_id " +
|
|
114
|
+
"WHERE g.taggable_type = 'document' AND g.taggable_id = d.id AND t.name = ?)",
|
|
115
|
+
params: [canonicalTagNamed(database, node.value)?.name ?? normalizeTag(node.value)],
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
person: {
|
|
119
|
+
where: (node) => {
|
|
120
|
+
let found;
|
|
121
|
+
try {
|
|
122
|
+
found = thingOf(database, node.value.startsWith("person:") ? node.value : `person:${node.value}`);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
found = undefined;
|
|
126
|
+
}
|
|
127
|
+
if (!found)
|
|
128
|
+
return { sql: "0", params: [], known: true };
|
|
129
|
+
return {
|
|
130
|
+
sql: "EXISTS (SELECT 1 FROM links l WHERE l.from_type = 'document' AND l.from_id = d.id AND l.to_type = ? " +
|
|
131
|
+
"AND l.to_id IN (SELECT value FROM json_each(?)))",
|
|
132
|
+
params: [found.type, idsOf(database, found.type, found.id)],
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
const scoped = (filter, where) => {
|
|
139
|
+
const clauses = [LISTED];
|
|
140
|
+
const params = [];
|
|
141
|
+
if (filter.accountIds !== undefined) {
|
|
142
|
+
if (filter.accountIds.length === 0)
|
|
143
|
+
invalid("accountIds names no account");
|
|
144
|
+
clauses.push("d.account_id IN (SELECT value FROM json_each(?))");
|
|
145
|
+
params.push(JSON.stringify(filter.accountIds));
|
|
146
|
+
}
|
|
147
|
+
if (where) {
|
|
148
|
+
clauses.push(`(${where.sql})`);
|
|
149
|
+
for (const param of where.params)
|
|
150
|
+
params.push(param);
|
|
151
|
+
}
|
|
152
|
+
return { sql: clauses.join(" AND "), params };
|
|
153
|
+
};
|
|
154
|
+
const FROM = `FROM documents d JOIN accounts a ON a.id = d.account_id ${PREFERRED}`;
|
|
155
|
+
const treeOf = (paths, depth) => {
|
|
156
|
+
const root = { name: "", path: "", count: 0, folders: [] };
|
|
157
|
+
let loose = 0;
|
|
158
|
+
for (const [folder, count] of paths) {
|
|
159
|
+
if (folder === "") {
|
|
160
|
+
loose += count;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
let at = root;
|
|
164
|
+
const parts = folder.split("/");
|
|
165
|
+
for (const [index, name] of parts.slice(0, depth).entries()) {
|
|
166
|
+
const path = parts.slice(0, index + 1).join("/");
|
|
167
|
+
let child = at.folders.find((one) => one.path === path);
|
|
168
|
+
if (!child) {
|
|
169
|
+
child = { name, path, count: 0, folders: [] };
|
|
170
|
+
at.folders.push(child);
|
|
171
|
+
}
|
|
172
|
+
child.count += count;
|
|
173
|
+
at = child;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const sort = (nodes) => {
|
|
177
|
+
nodes.sort((a, b) => a.name.localeCompare(b.name));
|
|
178
|
+
for (const node of nodes)
|
|
179
|
+
sort(node.folders);
|
|
180
|
+
};
|
|
181
|
+
sort(root.folders);
|
|
182
|
+
return { loose, folders: root.folders };
|
|
183
|
+
};
|
|
184
|
+
export const documentListingOver = (context) => {
|
|
185
|
+
const { database } = context;
|
|
186
|
+
const whereOf = (query, zone, now) => query && queryFilter(query, columns(context), { ...(zone ? { zone } : {}), ...(now ? { now } : {}) });
|
|
187
|
+
return {
|
|
188
|
+
documentAccounts: async () => database
|
|
189
|
+
.prepare(`SELECT id, provider, external_id, name FROM accounts WHERE id IN (SELECT d.account_id FROM documents d ` +
|
|
190
|
+
`WHERE ${LISTED}) ORDER BY provider, external_id`)
|
|
191
|
+
.all()
|
|
192
|
+
.map(accountOf),
|
|
193
|
+
documents: async (filter) => {
|
|
194
|
+
if (!Number.isInteger(filter.limit) || filter.limit < 1 || !Number.isInteger(filter.offset) || filter.offset < 0)
|
|
195
|
+
invalid("limit takes 1 or more and offset 0 or more");
|
|
196
|
+
if (filter.ids?.length === 0)
|
|
197
|
+
return { items: [], total: 0 };
|
|
198
|
+
const where = scoped(filter, whereOf(filter.query, filter.zone, filter.now));
|
|
199
|
+
// A text search's ids come ranked: joined as a table, their position orders the page.
|
|
200
|
+
const from = filter.ids ? `${FROM} JOIN json_each(?) k ON k.value = d.id` : FROM;
|
|
201
|
+
const ranked = filter.ids ? [JSON.stringify(filter.ids)] : [];
|
|
202
|
+
const order = filter.ids ? "k.key" : `${MODIFIED} DESC, d.id DESC`;
|
|
203
|
+
return read(database, () => {
|
|
204
|
+
// Counted apart: a window count would make SQLite build every row's columns before the page is cut.
|
|
205
|
+
const total = Number(database.prepare(`SELECT count(*) AS n ${from} WHERE ${where.sql}`).get(...ranked, ...where.params)?.n);
|
|
206
|
+
// The page's ids first, then its columns: SQLite would build every row's kind and path before the cut.
|
|
207
|
+
const page = database
|
|
208
|
+
.prepare(`SELECT d.id ${from} WHERE ${where.sql} ORDER BY ${order} LIMIT ? OFFSET ?`)
|
|
209
|
+
.all(...ranked, ...where.params, filter.limit, filter.offset)
|
|
210
|
+
.map(({ id }) => Number(id));
|
|
211
|
+
const found = database
|
|
212
|
+
.prepare(`SELECT ${COLUMNS} ${FROM} JOIN json_each(?) p ON p.value = d.id ORDER BY p.key`)
|
|
213
|
+
.all(JSON.stringify(page));
|
|
214
|
+
return { items: found.map(rowOf), total };
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
documentSources: async ({ accountIds, depth }) => {
|
|
218
|
+
const where = scoped({ ...(accountIds ? { accountIds } : {}) }, undefined);
|
|
219
|
+
return read(database, () => {
|
|
220
|
+
const rows = database
|
|
221
|
+
.prepare(`SELECT d.account_id, a.provider, a.external_id AS account, a.name AS account_name, ${PATH} AS path ${FROM} ` +
|
|
222
|
+
`WHERE ${where.sql}`)
|
|
223
|
+
.all(...where.params);
|
|
224
|
+
const byAccount = new Map();
|
|
225
|
+
for (const row of rows) {
|
|
226
|
+
const id = Number(row.account_id);
|
|
227
|
+
const held = byAccount.get(id) ?? { row, folders: new Map() };
|
|
228
|
+
byAccount.set(id, held);
|
|
229
|
+
const folder = folderOf(str(row.path)) ?? "";
|
|
230
|
+
held.folders.set(folder, (held.folders.get(folder) ?? 0) + 1);
|
|
231
|
+
}
|
|
232
|
+
return [...byAccount.entries()]
|
|
233
|
+
.map(([accountId, { row, folders }]) => ({
|
|
234
|
+
accountId,
|
|
235
|
+
provider: String(row.provider),
|
|
236
|
+
account: String(row.account),
|
|
237
|
+
name: str(row.account_name),
|
|
238
|
+
count: [...folders.values()].reduce((sum, count) => sum + count, 0),
|
|
239
|
+
...treeOf(folders, depth),
|
|
240
|
+
}))
|
|
241
|
+
.sort((a, b) => a.provider.localeCompare(b.provider) || a.account.localeCompare(b.account));
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
document: async (id, { offset, limit }) => read(database, () => {
|
|
245
|
+
const row = database
|
|
246
|
+
.prepare(`SELECT ${COLUMNS}, substr(d.body, ?, ?) AS text, length(d.body) AS text_length, d.extraction,
|
|
247
|
+
d.extraction_error, d.language ${FROM} WHERE d.id = ? AND ${LISTED}`)
|
|
248
|
+
.get(offset + 1, limit, id);
|
|
249
|
+
if (!row)
|
|
250
|
+
return undefined;
|
|
251
|
+
const tags = database
|
|
252
|
+
.prepare("SELECT t.name FROM taggings g JOIN resolved_tags t ON t.id = g.tag_id " +
|
|
253
|
+
"WHERE g.taggable_type = 'document' AND g.taggable_id = ? ORDER BY t.name")
|
|
254
|
+
.all(id)
|
|
255
|
+
.map((tag) => String(tag.name));
|
|
256
|
+
const people = database
|
|
257
|
+
.prepare("SELECT DISTINCT p.id, p.name, l.kind FROM links l JOIN persons p ON p.id = l.to_id " +
|
|
258
|
+
"WHERE l.from_type = 'document' AND l.from_id = ? AND l.to_type = 'person' ORDER BY p.name, p.id")
|
|
259
|
+
.all(id)
|
|
260
|
+
.map((person) => ({ ref: `person:${person.id}`, name: str(person.name), kind: String(person.kind) }));
|
|
261
|
+
const meetings = database
|
|
262
|
+
.prepare("SELECT m.id, m.account_id, m.title, m.started_at, l.role FROM links l JOIN meetings m ON m.id = l.from_id " +
|
|
263
|
+
"WHERE l.from_type = 'meeting' AND l.to_type = 'document' AND l.to_id = ? AND l.kind = 'attached' " +
|
|
264
|
+
"AND m.deleted_at IS NULL ORDER BY m.started_at DESC, m.id")
|
|
265
|
+
.all(id)
|
|
266
|
+
.map((meeting) => ({
|
|
267
|
+
ref: `meeting:${meeting.account_id}/${meeting.id}`,
|
|
268
|
+
title: str(meeting.title),
|
|
269
|
+
at: num(meeting.started_at),
|
|
270
|
+
role: str(meeting.role),
|
|
271
|
+
}));
|
|
272
|
+
const events = database
|
|
273
|
+
.prepare("SELECT DISTINCT e.id, e.title, e.starts_at FROM links l JOIN calendar_entries ce ON ce.id = l.from_id " +
|
|
274
|
+
"JOIN events e ON e.id = ce.event_id WHERE l.from_type = 'calendar_entry' AND l.to_type = 'document' " +
|
|
275
|
+
"AND l.to_id = ? AND l.kind = 'attached' AND e.deleted_at IS NULL ORDER BY e.starts_at DESC, e.id")
|
|
276
|
+
.all(id)
|
|
277
|
+
.map((event) => ({ ref: `event:${event.id}`, title: str(event.title), at: num(event.starts_at), role: null }));
|
|
278
|
+
return {
|
|
279
|
+
...rowOf(row),
|
|
280
|
+
text: str(row.text),
|
|
281
|
+
textLength: Number(row.text_length ?? 0),
|
|
282
|
+
extraction: str(row.extraction),
|
|
283
|
+
extractionError: str(row.extraction_error),
|
|
284
|
+
language: str(row.language),
|
|
285
|
+
tags,
|
|
286
|
+
people,
|
|
287
|
+
meetings,
|
|
288
|
+
events,
|
|
289
|
+
};
|
|
290
|
+
}),
|
|
291
|
+
};
|
|
292
|
+
};
|
|
@@ -90,6 +90,8 @@ export declare const fileOf: (row: Row) => StoredFile;
|
|
|
90
90
|
* Read with the document's row joined as `d`.
|
|
91
91
|
*/
|
|
92
92
|
export declare const PREFERRED_FILE = "f.deleted_at IS NOT NULL, f.id IS NOT d.pinned_file_id, coalesce(f.external_updated_at, f.updated_at) DESC, f.id DESC";
|
|
93
|
+
/** The folded paths under a folder, as one range over the index: `/` sorts just before `0`. */
|
|
94
|
+
export declare const subtreeOf: (folder: string) => [low: string, high: string];
|
|
93
95
|
export declare const filesStoreOver: ({ database, now }: {
|
|
94
96
|
database: CacheDatabase;
|
|
95
97
|
now: () => number;
|
|
@@ -256,6 +256,11 @@ export const fileOf = (row) => ({
|
|
|
256
256
|
* Read with the document's row joined as `d`.
|
|
257
257
|
*/
|
|
258
258
|
export const PREFERRED_FILE = "f.deleted_at IS NOT NULL, f.id IS NOT d.pinned_file_id, coalesce(f.external_updated_at, f.updated_at) DESC, f.id DESC";
|
|
259
|
+
/** The folded paths under a folder, as one range over the index: `/` sorts just before `0`. */
|
|
260
|
+
export const subtreeOf = (folder) => {
|
|
261
|
+
const prefix = fold(folder.replace(/\/+$/u, ""));
|
|
262
|
+
return [`${prefix}/`, `${prefix}0`];
|
|
263
|
+
};
|
|
259
264
|
export const filesStoreOver = ({ database, now }) => {
|
|
260
265
|
const account = (id) => {
|
|
261
266
|
if (!/^\d+$/.test(id) || !database.prepare("SELECT 1 FROM accounts WHERE id = ?").get(Number(id)))
|
|
@@ -276,10 +281,9 @@ export const filesStoreOver = ({ database, now }) => {
|
|
|
276
281
|
params.push(query.kind);
|
|
277
282
|
}
|
|
278
283
|
if (query.under !== undefined) {
|
|
279
|
-
const
|
|
280
|
-
// `/` sorts just before `0`, so the subtree is one range over the index.
|
|
284
|
+
const [low, high] = subtreeOf(query.under);
|
|
281
285
|
clauses.push("(f.path_folded = ? OR (f.path_folded >= ? AND f.path_folded < ?))");
|
|
282
|
-
params.push(
|
|
286
|
+
params.push(fold(query.under.replace(/\/+$/u, "")), low, high);
|
|
283
287
|
}
|
|
284
288
|
if (query.pathContains !== undefined) {
|
|
285
289
|
clauses.push("instr(f.path_folded, ?) > 0");
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { StoreContext } from "./open.js";
|
|
2
|
+
export declare const MEETING_ROW_KINDS: readonly ["meeting", "call", "event"];
|
|
3
|
+
export type MeetingRowKind = (typeof MEETING_ROW_KINDS)[number];
|
|
4
|
+
export interface MeetingListFilter {
|
|
5
|
+
/** Rows that end after this instant. */
|
|
6
|
+
from?: number;
|
|
7
|
+
/** Rows that start before this instant. */
|
|
8
|
+
to?: number;
|
|
9
|
+
/** The local days an all-day event is compared by, as `EventFilter` has them. */
|
|
10
|
+
fromDate?: string;
|
|
11
|
+
toDate?: string;
|
|
12
|
+
/** Rows with a calendar copy or a meeting in these stored accounts; every account when left out. */
|
|
13
|
+
accountIds?: readonly number[];
|
|
14
|
+
kinds?: readonly MeetingRowKind[];
|
|
15
|
+
/** A person's id: rows they were invited to, took part in, or were called by. */
|
|
16
|
+
personId?: number;
|
|
17
|
+
hasTranscript?: boolean;
|
|
18
|
+
/** Words every title holds, compared folded. */
|
|
19
|
+
titleWords?: readonly string[];
|
|
20
|
+
newest?: boolean;
|
|
21
|
+
limit: number;
|
|
22
|
+
offset: number;
|
|
23
|
+
}
|
|
24
|
+
export interface MeetingRowSource {
|
|
25
|
+
provider: string;
|
|
26
|
+
account: string;
|
|
27
|
+
/** `calendar`: a copy in a calendar; `meeting`: a meeting provider's record. */
|
|
28
|
+
via: "calendar" | "meeting";
|
|
29
|
+
/** The calendar's title, for a calendar copy. */
|
|
30
|
+
calendar: string | null;
|
|
31
|
+
/** `meeting:<account>/<id>` for a meeting, `event:<id>` for a calendar copy. */
|
|
32
|
+
ref: string;
|
|
33
|
+
}
|
|
34
|
+
export interface MeetingRowParticipant {
|
|
35
|
+
name: string | null;
|
|
36
|
+
email: string | null;
|
|
37
|
+
/** The person the store links the address or account to. */
|
|
38
|
+
person: {
|
|
39
|
+
ref: string;
|
|
40
|
+
name: string | null;
|
|
41
|
+
} | null;
|
|
42
|
+
organizer: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface MeetingRowDocument {
|
|
45
|
+
ref: string;
|
|
46
|
+
title: string | null;
|
|
47
|
+
role: string | null;
|
|
48
|
+
}
|
|
49
|
+
export interface MeetingRow {
|
|
50
|
+
type: "event" | "meeting";
|
|
51
|
+
id: number;
|
|
52
|
+
kind: MeetingRowKind;
|
|
53
|
+
title: string | null;
|
|
54
|
+
startsAt: number | null;
|
|
55
|
+
endsAt: number | null;
|
|
56
|
+
allDay: boolean;
|
|
57
|
+
timezone: string | null;
|
|
58
|
+
status: string | null;
|
|
59
|
+
url: string | null;
|
|
60
|
+
/** Each distinct join link, `provider:account` of the copy or meeting that gave it. */
|
|
61
|
+
links: {
|
|
62
|
+
source: string;
|
|
63
|
+
url: string;
|
|
64
|
+
}[];
|
|
65
|
+
/** The meetings on this row, by their stored ids, oldest first. */
|
|
66
|
+
meetings: {
|
|
67
|
+
id: number;
|
|
68
|
+
accountId: number;
|
|
69
|
+
}[];
|
|
70
|
+
sources: MeetingRowSource[];
|
|
71
|
+
participants: MeetingRowParticipant[];
|
|
72
|
+
hasRecording: boolean;
|
|
73
|
+
hasTranscript: boolean;
|
|
74
|
+
hasSummary: boolean;
|
|
75
|
+
documents: MeetingRowDocument[];
|
|
76
|
+
/** Findings in batches still waiting for the owner that cite one of the row's meetings. */
|
|
77
|
+
pendingFindings: number;
|
|
78
|
+
/** Every findings batch citing one of its meetings, newest first, with how many of its findings do. */
|
|
79
|
+
findings: {
|
|
80
|
+
id: string;
|
|
81
|
+
status: "proposed" | "reviewed";
|
|
82
|
+
findings: number;
|
|
83
|
+
pending: number;
|
|
84
|
+
}[];
|
|
85
|
+
}
|
|
86
|
+
export interface ListedAccount {
|
|
87
|
+
id: number;
|
|
88
|
+
provider: string;
|
|
89
|
+
account: string;
|
|
90
|
+
name: string | null;
|
|
91
|
+
}
|
|
92
|
+
export interface MeetingListing {
|
|
93
|
+
/** Every account holding a calendar or a meeting: what a list reads when no source narrows it. */
|
|
94
|
+
meetingAccounts(): Promise<ListedAccount[]>;
|
|
95
|
+
/** Meetings, calls and events as one row per real meeting, newest first unless `newest` is false. */
|
|
96
|
+
meetingRows(filter: MeetingListFilter): Promise<{
|
|
97
|
+
items: MeetingRow[];
|
|
98
|
+
total: number;
|
|
99
|
+
}>;
|
|
100
|
+
/** The row an `event:<id>` or a meeting (by account and id) is on, the same way a list shows it. */
|
|
101
|
+
meetingRow(target: {
|
|
102
|
+
event: number;
|
|
103
|
+
} | {
|
|
104
|
+
meeting: number;
|
|
105
|
+
}): Promise<MeetingRow | undefined>;
|
|
106
|
+
}
|
|
107
|
+
export declare const accountOf: (row: Record<string, unknown>) => ListedAccount;
|
|
108
|
+
export declare const meetingListingOver: (context: StoreContext) => MeetingListing;
|