@vite-hub/comments 0.4.1 → 0.5.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 (59) hide show
  1. package/README.md +19 -7
  2. package/dist/anchor.d.ts +2 -2
  3. package/dist/client.d.ts +424 -11
  4. package/dist/client.js +405 -5
  5. package/dist/{console-h4KlhIik.d.ts → console-D1lwNMZn.d.ts} +2 -0
  6. package/dist/{migrate-Bpw3xL5e.js → database-6hXRnqDE.js} +47 -2
  7. package/dist/database-CTo7mx6t.d.ts +575 -0
  8. package/dist/database.d.ts +2 -1
  9. package/dist/database.js +2 -2
  10. package/dist/{define-CX_Yr_hz.js → define-BMBSVbD9.js} +1 -1
  11. package/dist/{define-CHTWfHPo.d.ts → define-CmIFU96x.d.ts} +8 -4
  12. package/dist/{errors-4gelGVmK.js → errors-BJTZ9iyv.js} +24 -0
  13. package/dist/{errors-BHsVXlpd.js → errors-Dq4AHjza.js} +16 -0
  14. package/dist/{index-iPGlSAgj.d.ts → index-RiHzmV16.d.ts} +113 -11
  15. package/dist/index.d.ts +6 -7
  16. package/dist/index.js +21 -7
  17. package/dist/{install-96NXWnrw.d.ts → install-BGGQKbQ4.d.ts} +9 -3
  18. package/dist/{install-jRKmuLHK.js → install-DrAse1Fa.js} +844 -38
  19. package/dist/{installed-g6nDr5ac.js → installed-C3EoqJEY.js} +7 -6
  20. package/dist/{operations-D93EV10O.d.ts → operations-BKhUWYkb.d.ts} +9 -5
  21. package/dist/{operations-7ycAhDCw.d.ts → operations-VyyNZusz.d.ts} +8 -2
  22. package/dist/{operations-9tskoLsk.js → operations-lsVKE0GH.js} +294 -212
  23. package/dist/operations.d.ts +2 -2
  24. package/dist/operations.js +2 -2
  25. package/dist/overlay/{client-lZesR40x.js → client-DBmJ4C1M.js} +1 -1
  26. package/dist/overlay/overlay.js +36 -40
  27. package/dist/page/loader.js +39 -47
  28. package/dist/{page-CWwnmF3K.d.ts → page-Bzj0CszG.d.ts} +1 -10
  29. package/dist/{page-tools-shared-NHUjKI8E.js → page-tools-shared-BNnuPK93.js} +6 -3
  30. package/dist/{plugin-BNFd1zGz.js → plugin-DRsNaJaK.js} +14 -9
  31. package/dist/realtime.d.ts +2 -2
  32. package/dist/realtime.js +1 -1
  33. package/dist/request-log-Dj9Vw7qG.js +105 -0
  34. package/dist/request-origin-CFU0TQ7E.js +49 -0
  35. package/dist/{rpc-BZ1QNkCC.d.ts → rpc-CuJ5GLIz.d.ts} +1 -1
  36. package/dist/rpc.d.ts +1 -1
  37. package/dist/runtime/auth.d.ts +2 -2
  38. package/dist/runtime/auth.js +1 -1
  39. package/dist/runtime/console.d.ts +1 -1
  40. package/dist/runtime/console.js +1 -1
  41. package/dist/runtime/index.d.ts +11 -9
  42. package/dist/runtime/index.js +148 -14
  43. package/dist/{server-CqyzrqTI.js → server-Yk610niJ.js} +1 -1
  44. package/dist/server.d.ts +6 -5
  45. package/dist/server.js +5 -5
  46. package/dist/service-Bj-Mg63c.d.ts +73 -0
  47. package/dist/{service-C8ZgFWvy.js → service-DA5BwfPQ.js} +39 -11
  48. package/dist/{session-CKfW6DGE.d.ts → session-DUcEor2W.d.ts} +3 -3
  49. package/dist/{session-ByjMyTak.js → session-X_g9dnU5.js} +26 -29
  50. package/dist/{service-wC9kx9EX.d.ts → store-CsUNfC1w.d.ts} +2 -70
  51. package/dist/{table-names-DfiKUlOV.js → table-names-B9LlRC0B.js} +3 -1
  52. package/dist/testing.d.ts +1 -1
  53. package/dist/testing.js +2 -2
  54. package/dist/{types-C7LzhgRb.d.ts → types-BLaYh0_f.d.ts} +1 -1
  55. package/dist/{types-C1qzObs2.d.ts → types-C35INXIs.d.ts} +79 -4
  56. package/dist/vite.d.ts +22 -5
  57. package/dist/vite.js +140 -65
  58. package/package.json +8 -8
  59. package/dist/errors-BEChnUo7.d.ts +0 -197
package/dist/client.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { i as commentsUnansweredError, r as commentsClientDiagnostics, t as commentsAnswerError } from "./client-diagnostics-Bubm7Shd.js";
2
2
  import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf, t as failedCommentPreparation } from "./client-files-CJZl5Kc4.js";
3
3
  import { t as replyMessageId } from "./reply-id-P_bSuEng.js";
4
- import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
5
- import { t as foldName } from "./fold-name-B7Zb3-MF.js";
4
+ import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
6
5
  import { i as commentsRoute } from "./page-DRz_sDY4.js";
7
6
  import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
7
+ import { t as foldName } from "./fold-name-B7Zb3-MF.js";
8
8
  //#region ../internal/src/browser-environment.ts
9
9
  /** The real browser: window events, Web Locks, and a BroadcastChannel, each only when the browser has it. */
10
10
  function createBrowserEnvironment(options) {
@@ -422,7 +422,7 @@ function createOutbox(options, host) {
422
422
  });
423
423
  } else {
424
424
  const threadId = realId(entry.input.threadId);
425
- const subject = entry.subject ?? serverThread(threadId)?.subject ?? (files.files?.length ? (await host.transport.get({ id: threadId }))?.subject : void 0);
425
+ const subject = entry.subject ?? serverThread(threadId)?.subject ?? (files.files?.length ? (await host.transport.get({ threadId }))?.subject : void 0);
426
426
  if (files.files?.length && !subject) throw Object.assign(/* @__PURE__ */ new Error("The thread for this reply does not exist."), { status: 404 });
427
427
  if (!await withClaim(() => true)) return;
428
428
  writing = true;
@@ -1131,6 +1131,360 @@ function resolveAnchor(anchor, root = document) {
1131
1131
  };
1132
1132
  }
1133
1133
  //#endregion
1134
+ //#region src/client-send.ts
1135
+ const reasonOf = (error) => error instanceof Error ? error.message : String(error);
1136
+ /**
1137
+ * The Send segment of a comment pill, without a framework: it hands the member's waiting threads to their agent, and
1138
+ * pairs one in place first when there is none. `CommentSend` of `@vite-hub/ui` renders it.
1139
+ */
1140
+ function createCommentSend(transport, options = {}) {
1141
+ const pairingInterval = options.pairingInterval ?? 1500;
1142
+ const statusInterval = options.statusInterval ?? 5e3;
1143
+ const sentFor = options.sentFor ?? 2e3;
1144
+ const listeners = /* @__PURE__ */ new Set();
1145
+ let state = {
1146
+ status: "idle",
1147
+ count: 0,
1148
+ inbox: false
1149
+ };
1150
+ let agent;
1151
+ let count = 0;
1152
+ let countRevision = 0;
1153
+ let selection = "";
1154
+ let selections = 0;
1155
+ let code;
1156
+ let fetching = false;
1157
+ let sendId;
1158
+ let thread;
1159
+ let pushed;
1160
+ let step = 0;
1161
+ let timer;
1162
+ let run = 0;
1163
+ const notify = () => {
1164
+ for (const listener of listeners) listener();
1165
+ };
1166
+ const set = (next) => {
1167
+ step++;
1168
+ clearTimeout(timer);
1169
+ timer = void 0;
1170
+ state = next;
1171
+ notify();
1172
+ };
1173
+ const later = (ms, then) => {
1174
+ const at = step;
1175
+ clearTimeout(timer);
1176
+ timer = setTimeout(() => at === step && then(), ms);
1177
+ };
1178
+ const inbox = () => Boolean(agent && !agent.host);
1179
+ const idleState = () => ({
1180
+ status: "idle",
1181
+ count,
1182
+ inbox: inbox(),
1183
+ ...agent && count > 0 ? { canPairAnother: true } : {}
1184
+ });
1185
+ const idle = () => set(idleState());
1186
+ const finish = () => {
1187
+ sendId = void 0;
1188
+ thread = void 0;
1189
+ idle();
1190
+ };
1191
+ const working = () => {
1192
+ set({
1193
+ status: "working",
1194
+ count,
1195
+ ...agent ? { agent } : {},
1196
+ ...thread ? { thread } : {}
1197
+ });
1198
+ if (!transport.subscribe) later(statusInterval, () => void refresh(working));
1199
+ };
1200
+ const limited = (retryAt) => {
1201
+ set({
1202
+ status: "limited",
1203
+ count,
1204
+ retryAt
1205
+ });
1206
+ later(Math.max(0, retryAt - Date.now()), () => void refresh(idle));
1207
+ };
1208
+ const pending = () => {
1209
+ set({
1210
+ status: "sending",
1211
+ count
1212
+ });
1213
+ later(statusInterval, () => void refresh(pending, true));
1214
+ };
1215
+ const apply = (status) => {
1216
+ agent = status.agent;
1217
+ if (status.pending) return pending();
1218
+ if (status.working) {
1219
+ sendId = status.working.id;
1220
+ thread = status.working.thread;
1221
+ if (state.status === "sent") {
1222
+ state = {
1223
+ ...state,
1224
+ count,
1225
+ inbox: inbox()
1226
+ };
1227
+ return notify();
1228
+ }
1229
+ return working();
1230
+ }
1231
+ sendId = void 0;
1232
+ thread = void 0;
1233
+ if (status.retryAt !== void 0 && status.retryAt > Date.now()) return limited(status.retryAt);
1234
+ idle();
1235
+ };
1236
+ const refresh = async (onError, deliveryPending = false) => {
1237
+ const at = step;
1238
+ const canApply = () => at === step && !fetching && state.status !== "pairing" && state.status !== "confirm" && (state.status !== "sending" || deliveryPending);
1239
+ if (!canApply()) return;
1240
+ const revision = countRevision;
1241
+ try {
1242
+ const status = await transport.status();
1243
+ if (!canApply()) return;
1244
+ if (revision === countRevision) count = status.count;
1245
+ selection = status.selection ?? "";
1246
+ apply(status);
1247
+ } catch (error) {
1248
+ if (!onError) throw error;
1249
+ if (canApply()) onError();
1250
+ }
1251
+ };
1252
+ const settle = (result, revision, paired) => {
1253
+ const updates = pushed;
1254
+ pushed = void 0;
1255
+ if (result.status === "changed") {
1256
+ count = result.count;
1257
+ selection = result.selection;
1258
+ if (!paired) return set({
1259
+ status: "failed",
1260
+ count,
1261
+ reason: "The waiting comments changed."
1262
+ });
1263
+ code = paired.code;
1264
+ return set({
1265
+ status: "confirm",
1266
+ count,
1267
+ agent: paired.agent
1268
+ });
1269
+ }
1270
+ if (result.status === "failed") return set({
1271
+ status: "failed",
1272
+ count,
1273
+ reason: result.reason
1274
+ });
1275
+ if (paired) agent = paired.agent;
1276
+ if (result.status === "limited") return limited(result.retryAt);
1277
+ if (result.status === "pending") return pending();
1278
+ sendId = result.id;
1279
+ const update = updates?.get(result.id);
1280
+ thread = update?.thread ?? result.thread;
1281
+ if (revision === countRevision) count = 0;
1282
+ set({
1283
+ status: "sent",
1284
+ count,
1285
+ inbox: inbox()
1286
+ });
1287
+ later(sentFor, update?.done ? finish : working);
1288
+ };
1289
+ const deliver = async (request, paired) => {
1290
+ const revision = countRevision;
1291
+ pushed = transport.subscribe ? /* @__PURE__ */ new Map() : void 0;
1292
+ set({
1293
+ status: "sending",
1294
+ count
1295
+ });
1296
+ const at = step;
1297
+ let result;
1298
+ try {
1299
+ result = await request();
1300
+ } catch (error) {
1301
+ result = {
1302
+ status: "failed",
1303
+ reason: reasonOf(error)
1304
+ };
1305
+ }
1306
+ if (at === step) settle(result, revision, paired);
1307
+ };
1308
+ const drop = (dropped) => void transport.cancel(dropped).catch(() => void 0);
1309
+ const poll = () => {
1310
+ later(pairingInterval, async () => {
1311
+ if (state.status !== "pairing" || !code) return;
1312
+ if (Date.now() >= state.expiresAt) return set({
1313
+ ...state,
1314
+ reason: "expired"
1315
+ });
1316
+ const at = step;
1317
+ const check = await transport.pollPairing(code).catch(() => ({ status: "waiting" }));
1318
+ if (at !== step || state.status !== "pairing") return;
1319
+ if (check.status === "waiting") return poll();
1320
+ if (check.status === "paired") return set({
1321
+ status: "confirm",
1322
+ count,
1323
+ agent: check.agent
1324
+ });
1325
+ set({
1326
+ ...state,
1327
+ reason: check.status
1328
+ });
1329
+ });
1330
+ };
1331
+ const pair = async (copy) => {
1332
+ if (fetching) return;
1333
+ fetching = true;
1334
+ const at = ++step;
1335
+ try {
1336
+ const pairing = transport.startPairing();
1337
+ const prompt = pairing.then((next) => next.prompt);
1338
+ prompt.catch(() => void 0);
1339
+ const copied = (async () => copy ? copy(prompt) : true)().then((ok) => ({ ok }), (error) => ({
1340
+ ok: false,
1341
+ error
1342
+ }));
1343
+ const next = await pairing;
1344
+ const outcome = await copied;
1345
+ if (at !== step) return drop(next.code);
1346
+ fetching = false;
1347
+ if (!outcome.ok) {
1348
+ drop(next.code);
1349
+ const reason = "error" in outcome ? reasonOf(outcome.error) : "The browser did not let the page copy the setup prompt.";
1350
+ return set({
1351
+ status: "failed",
1352
+ count,
1353
+ reason
1354
+ });
1355
+ }
1356
+ if (code) drop(code);
1357
+ code = next.code;
1358
+ count = next.count;
1359
+ selection = next.selection;
1360
+ set({
1361
+ status: "pairing",
1362
+ count,
1363
+ prompt: next.prompt,
1364
+ expiresAt: next.expiresAt,
1365
+ agent: next.agent
1366
+ });
1367
+ poll();
1368
+ } catch (error) {
1369
+ if (at === step) {
1370
+ fetching = false;
1371
+ set({
1372
+ status: "failed",
1373
+ count,
1374
+ reason: reasonOf(error)
1375
+ });
1376
+ }
1377
+ }
1378
+ };
1379
+ const reselect = async () => {
1380
+ const at = ++selections;
1381
+ const pairing = code;
1382
+ const status = await transport.status().catch(() => void 0);
1383
+ if (!status || at !== selections || !pairing || pairing !== code || state.status !== "pairing" && state.status !== "confirm") return;
1384
+ count = status.count;
1385
+ selection = status.selection ?? "";
1386
+ state = {
1387
+ ...state,
1388
+ count
1389
+ };
1390
+ notify();
1391
+ };
1392
+ return {
1393
+ get state() {
1394
+ return state;
1395
+ },
1396
+ onChange(listener) {
1397
+ listeners.add(listener);
1398
+ return () => {
1399
+ listeners.delete(listener);
1400
+ };
1401
+ },
1402
+ start() {
1403
+ const current = ++run;
1404
+ const stop = transport.subscribe?.((event) => {
1405
+ if (current !== run) return;
1406
+ if (event.type === "count") {
1407
+ countRevision++;
1408
+ if (state.status === "pairing" || state.status === "confirm") return void reselect();
1409
+ count = event.count;
1410
+ if (state.status !== "sending") {
1411
+ state = state.status === "idle" ? idleState() : {
1412
+ ...state,
1413
+ count
1414
+ };
1415
+ notify();
1416
+ }
1417
+ return;
1418
+ }
1419
+ if (state.status === "sending") {
1420
+ const update = pushed?.get(event.id);
1421
+ pushed?.set(event.id, event.type === "done" ? {
1422
+ ...update,
1423
+ done: true
1424
+ } : {
1425
+ ...update,
1426
+ thread: event.thread ?? update?.thread
1427
+ });
1428
+ return;
1429
+ }
1430
+ if (fetching || state.status === "pairing" || state.status === "confirm") return;
1431
+ if ((state.status === "working" || state.status === "sent") && sendId !== event.id) return;
1432
+ if (event.type === "working") {
1433
+ thread = event.thread ?? (event.id === sendId ? thread : void 0);
1434
+ sendId = event.id;
1435
+ if (state.status !== "sent") working();
1436
+ return;
1437
+ }
1438
+ if (event.id === sendId) finish();
1439
+ });
1440
+ refresh(() => void 0);
1441
+ return () => {
1442
+ stop?.();
1443
+ if (current !== run) return;
1444
+ run++;
1445
+ if (code) drop(code);
1446
+ code = void 0;
1447
+ fetching = false;
1448
+ pushed = void 0;
1449
+ agent = void 0;
1450
+ count = 0;
1451
+ finish();
1452
+ };
1453
+ },
1454
+ refresh: () => refresh(),
1455
+ async send(copy) {
1456
+ if (fetching || state.status !== "idle" && state.status !== "failed" && state.status !== "working") return;
1457
+ if (state.status !== "failed" && count === 0) return;
1458
+ if (!agent) return pair(copy);
1459
+ return deliver(() => transport.send());
1460
+ },
1461
+ async pairAnother(copy) {
1462
+ if (state.status !== "idle" || !state.canPairAnother) return;
1463
+ return pair(copy);
1464
+ },
1465
+ async allow() {
1466
+ if (state.status !== "confirm" || !code) return;
1467
+ const used = code;
1468
+ code = void 0;
1469
+ return deliver(() => transport.allow(used, selection), {
1470
+ code: used,
1471
+ agent: state.agent
1472
+ });
1473
+ },
1474
+ async copyAgain(copy) {
1475
+ if (state.status !== "pairing" || !state.reason) return;
1476
+ return pair(copy);
1477
+ },
1478
+ cancel() {
1479
+ if (state.status !== "pairing" && state.status !== "confirm") return;
1480
+ if (code) drop(code);
1481
+ code = void 0;
1482
+ fetching = false;
1483
+ idle();
1484
+ }
1485
+ };
1486
+ }
1487
+ //#endregion
1134
1488
  //#region src/rest-transport.ts
1135
1489
  /** The URL of an attachment key below the Comments API, such as `/_vitehub/comments/attachments/comments/<id>/shot.png`. */
1136
1490
  function commentAttachmentUrl(key, base = "") {
@@ -1227,7 +1581,7 @@ function createRestTransport(options = {}) {
1227
1581
  return (await request(`/threads?${listSearch(query)}`)).data;
1228
1582
  },
1229
1583
  async get(input) {
1230
- const path = "id" in input ? thread(input.id) : `/scopes/${encodeURIComponent(input.scope)}/threads/${input.n}`;
1584
+ const path = "threadId" in input ? thread(input.threadId) : `/scopes/${encodeURIComponent(input.scope)}/threads/${input.n}`;
1231
1585
  return (await request(path)).data;
1232
1586
  },
1233
1587
  async create({ files, outbox, ...input }) {
@@ -1277,6 +1631,52 @@ function createRestTransport(options = {}) {
1277
1631
  };
1278
1632
  }
1279
1633
  //#endregion
1634
+ //#region src/send-transport.ts
1635
+ /**
1636
+ * The transport of `createCommentSend()` over the Send routes of Comments, `<base>/_vitehub/comments/send/**`. The
1637
+ * ViteHub pill uses it, and an app renders `CommentSend` of `@vite-hub/ui` with it in its own pill:
1638
+ *
1639
+ * ```ts
1640
+ * import { createCommentSend, createCommentSendTransport } from "@vite-hub/comments/client"
1641
+ *
1642
+ * const send = createCommentSend(createCommentSendTransport({ page: () => location.pathname }))
1643
+ * ```
1644
+ */
1645
+ function createCommentSendTransport(options = {}) {
1646
+ const request = createCommentsRestRequest(options);
1647
+ const page = () => encodeURIComponent(typeof options.page === "function" ? options.page() : options.page ?? location.pathname);
1648
+ const post = (body) => ({
1649
+ method: "POST",
1650
+ ...body === void 0 ? {} : { body: JSON.stringify(body) }
1651
+ });
1652
+ const code = (value) => encodeURIComponent(value);
1653
+ const pairingPages = /* @__PURE__ */ new Map();
1654
+ return {
1655
+ status: async () => (await request(`/send/status?page=${page()}`)).data,
1656
+ startPairing: async () => {
1657
+ const path = page();
1658
+ const pairing = (await request(`/send/start?page=${path}`, post())).data;
1659
+ pairingPages.set(pairing.code, path);
1660
+ return pairing;
1661
+ },
1662
+ pollPairing: async (value) => (await request(`/send/pair/${code(value)}`)).data,
1663
+ allow: async (value, selection) => {
1664
+ const path = pairingPages.get(value) ?? page();
1665
+ const result = (await request(`/send/allow?page=${path}`, post({
1666
+ code: value,
1667
+ selection
1668
+ }))).data;
1669
+ if (result.status !== "changed") pairingPages.delete(value);
1670
+ return result;
1671
+ },
1672
+ cancel: async (value) => {
1673
+ pairingPages.delete(value);
1674
+ await request(`/send/pair/${code(value)}`, { method: "DELETE" });
1675
+ },
1676
+ send: async () => (await request(`/send?page=${page()}`, post())).data
1677
+ };
1678
+ }
1679
+ //#endregion
1280
1680
  //#region src/client.ts
1281
1681
  function createCommentsClient(options) {
1282
1682
  const { transport } = options;
@@ -1510,4 +1910,4 @@ function createCommentsClient(options) {
1510
1910
  };
1511
1911
  }
1512
1912
  //#endregion
1513
- export { anchorRange, commentAttachmentUrl, commentsErrorDiagnostics, createAnchor, createCommentsClient, createCommentsRestRequest, createIndexedDBOutboxStore, createMemoryOutboxStore, createRestTransport, foldName, replyMessageId, resolveAnchor, selectorFor };
1913
+ export { anchorRange, commentAttachmentUrl, commentsErrorDiagnostics, createAnchor, createCommentSend, createCommentSendTransport, createCommentsClient, createCommentsRestRequest, createIndexedDBOutboxStore, createMemoryOutboxStore, createRestTransport, foldName, replyMessageId, resolveAnchor, selectorFor };
@@ -48,6 +48,8 @@ interface ViteHubResourceSummary {
48
48
  owner: string;
49
49
  /** Absent when no id is known yet. */
50
50
  source?: ViteHubResourceIdSource;
51
+ /** The resource is in the Wrangler config of a standalone Provider Output Worker, not in Nitro's. */
52
+ standalone?: boolean;
51
53
  }
52
54
  interface ViteHubInspectionContributor {
53
55
  definitions?: readonly ViteHubDefinitionInspector[];
@@ -1,4 +1,4 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
2
2
  import { sql } from "drizzle-orm";
3
3
  import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
4
4
  //#region src/operations-core/database.ts
@@ -286,4 +286,49 @@ function commentsSchemaGate(db, owner, options = {}) {
286
286
  };
287
287
  }
288
288
  //#endregion
289
- export { migrateComments as a, commentForge as c, commentsSchema as d, liveThreadsBackup as i, commentMessages as l, commentsSchemaGate as n, commentsTables as o, commentsSchemaState as r, commentCounters as s, commentsMigrationSql as t, commentThreads as u };
289
+ //#region src/send/database.ts
290
+ /**
291
+ * One row for each send: the member, the threads it carried with the last message of each, and the read token. `threads`
292
+ * holds JSON, `[{ id, message, role }]`, and `sender` the member as Comments knew them when they sent. The token is
293
+ * kept as its SHA-256 hash.
294
+ */
295
+ const commentSends = sqliteTable("vitehub_comment_sends", {
296
+ id: text("id").primaryKey(),
297
+ member: text("member").notNull(),
298
+ subjectKind: text("subject_kind").notNull(),
299
+ subjectId: text("subject_id").notNull(),
300
+ page: text("page").notNull(),
301
+ threads: text("threads").notNull(),
302
+ key: text("key").notNull(),
303
+ state: text("state", { enum: [
304
+ "pending",
305
+ "sent",
306
+ "working",
307
+ "done",
308
+ "failed"
309
+ ] }).notNull(),
310
+ delivery: text("delivery"),
311
+ endpoint: text("endpoint"),
312
+ thread: text("thread"),
313
+ error: text("error"),
314
+ sender: text("sender").notNull(),
315
+ tokenHash: text("token_hash"),
316
+ tokenExpiresAt: integer("token_expires_at"),
317
+ createdAt: integer("created_at").notNull(),
318
+ updatedAt: integer("updated_at").notNull()
319
+ }, (table) => [
320
+ index("vitehub_comment_sends_member").on(table.member, table.createdAt),
321
+ index("vitehub_comment_sends_subject").on(table.subjectKind, table.subjectId, table.createdAt),
322
+ uniqueIndex("vitehub_comment_sends_live_key").on(table.key).where(sql`${table.state} <> 'failed'`)
323
+ ]);
324
+ /** The tables of Send, for a Database contribution. Comments adds them only when `defineComments({ send })` is on. */
325
+ const commentSendsSchema = { commentSends };
326
+ /** `commentSendsSchema` as SQLite statements that are safe to run on every start. */
327
+ const commentSendsTables = [
328
+ "CREATE TABLE IF NOT EXISTS `vitehub_comment_sends` (`id` text PRIMARY KEY NOT NULL, `member` text NOT NULL, `subject_kind` text NOT NULL, `subject_id` text NOT NULL, `page` text NOT NULL, `threads` text NOT NULL, `key` text NOT NULL, `state` text NOT NULL, `delivery` text, `endpoint` text, `thread` text, `error` text, `sender` text NOT NULL, `token_hash` text, `token_expires_at` integer, `created_at` integer NOT NULL, `updated_at` integer NOT NULL)",
329
+ "CREATE INDEX IF NOT EXISTS `vitehub_comment_sends_member` ON `vitehub_comment_sends` (`member`,`created_at`)",
330
+ "CREATE INDEX IF NOT EXISTS `vitehub_comment_sends_subject` ON `vitehub_comment_sends` (`subject_kind`,`subject_id`,`created_at`)",
331
+ "CREATE UNIQUE INDEX IF NOT EXISTS `vitehub_comment_sends_live_key` ON `vitehub_comment_sends` (`key`) WHERE `state` <> 'failed'"
332
+ ];
333
+ //#endregion
334
+ export { commentsSchemaGate as a, migrateComments as c, commentForge as d, commentMessages as f, commentsMigrationSql as i, commentsTables as l, commentsSchema as m, commentSendsSchema as n, commentsSchemaState as o, commentThreads as p, commentSendsTables as r, liveThreadsBackup as s, commentSends as t, commentCounters as u };