@vite-hub/comments 0.5.0 → 0.6.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/README.md +7 -1
- package/dist/anchor.d.ts +3 -5
- package/dist/anchor.js +1 -2
- package/dist/{client-diagnostics-Bubm7Shd.js → client-diagnostics-CvfTW5d4.js} +1 -2
- package/dist/{client-files-CJZl5Kc4.js → client-files-lC6X7XyS.js} +1 -2
- package/dist/client.d.ts +44 -25
- package/dist/client.js +64 -43
- package/dist/{console-D1lwNMZn.d.ts → console-CCLX_eIk.d.ts} +1 -5
- package/dist/{context-BqIsmYP1.js → context-DbkBjITZ.js} +1 -2
- package/dist/database/postgres.d.ts +1 -3
- package/dist/database/postgres.js +1 -2
- package/dist/{database-6hXRnqDE.js → database-BkPoOdZr.js} +73 -61
- package/dist/{database-CTo7mx6t.d.ts → database-CPua6Q6_.d.ts} +0 -2
- package/dist/{database-CA1aHKN7.d.ts → database-DUs3c2al.d.ts} +625 -73
- package/dist/database.d.ts +4 -6
- package/dist/database.js +1 -2
- package/dist/{define-CmIFU96x.d.ts → define-B1jLSPe9.d.ts} +1 -3
- package/dist/{define-BMBSVbD9.js → define-BCxNaSZv.js} +3 -4
- package/dist/{errors-BJTZ9iyv.js → errors-C0VwRHiy.js} +1 -2
- package/dist/{errors-Dq4AHjza.js → errors-DFNiJg67.js} +10 -3
- package/dist/{fold-name-B7Zb3-MF.js → fold-name-g-xg0mQk.js} +1 -2
- package/dist/hosted/hosted-comments/client-B3dlmmQd.js +4 -0
- package/dist/{overlay/dist-BoHMOFax.js → hosted/hosted-comments/dist-DyVmH21U.js} +1 -1
- package/dist/hosted/hosted-comments/frame.js +1 -0
- package/dist/hosted/hosted-comments/overlay-CFuq5QAH.js +182 -0
- package/dist/hosted/hosted-comments/protocol-BHvtQKte.js +1 -0
- package/dist/hosted/hosted-comments/rest-transport-D-9_pNqZ.js +1 -0
- package/dist/hosted/hosted-comments/tools-Bz--joZw.js +126 -0
- package/dist/hosted/hosted-comments.js +9 -0
- package/dist/{identity-CBOzgxSf.js → identity-CT7-UGmS.js} +1 -2
- package/dist/{index-RiHzmV16.d.ts → index-D1T7RJ4R.d.ts} +10 -15
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -9
- package/dist/{install-BGGQKbQ4.d.ts → install-NehuMNhG.d.ts} +19 -8
- package/dist/{install-DrAse1Fa.js → install-w6CCgGFV.js} +158 -45
- package/dist/{installed-C3EoqJEY.js → installed-C9SkldMi.js} +2 -3
- package/dist/{invariant-D8_xBqmZ.js → invariant-CmdvZ3vp.js} +1 -2
- package/dist/{migrate-B0k_0swk.d.ts → migrate-XjFeQppf.d.ts} +2 -2
- package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
- package/dist/{operations-VyyNZusz.d.ts → operations-8hqTi0DH.d.ts} +0 -2
- package/dist/{operations-lsVKE0GH.js → operations-B8IMhRmY.js} +18 -20
- package/dist/{operations-BKhUWYkb.d.ts → operations-Cic9A9e_.d.ts} +4 -6
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/overlay/{client-DBmJ4C1M.js → client-CerbVjTz.js} +3 -3
- package/dist/overlay/dist-DyVmH21U.js +14 -0
- package/dist/overlay/overlay.js +28 -16
- package/dist/page/loader.js +22 -21
- package/dist/{page-Bzj0CszG.d.ts → page-DE71P_gQ.d.ts} +0 -2
- package/dist/{page-tools-shared-BNnuPK93.js → page-tools-shared-fvmJQCrP.js} +2 -2
- package/dist/{page-DRz_sDY4.js → page-xzgZ6DGm.js} +2 -3
- package/dist/{path--zk6PEMz.js → path-8yqMd8zR.js} +0 -1
- package/dist/{plugin-DRsNaJaK.js → plugin-DbCYT7Ac.js} +14 -11
- package/dist/realtime.d.ts +3 -5
- package/dist/realtime.js +4 -5
- package/dist/{reply-id-P_bSuEng.js → reply-id-Cm9FGOBs.js} +1 -2
- package/dist/{request-log-Dj9Vw7qG.js → request-log-DllKQXj7.js} +1 -2
- package/dist/{request-origin-CFU0TQ7E.js → request-origin-YPzfE2eh.js} +1 -2
- package/dist/{rpc-BQqYx8kb.js → rpc-BKY7XRlR.js} +5 -7
- package/dist/{rpc-CuJ5GLIz.d.ts → rpc-D-eqtyfh.d.ts} +1 -3
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +1 -2
- package/dist/runtime/auth.d.ts +3 -5
- package/dist/runtime/auth.js +2 -3
- package/dist/runtime/console.d.ts +2 -4
- package/dist/runtime/console.js +4 -5
- package/dist/runtime/index.d.ts +45 -32
- package/dist/runtime/index.js +27 -26
- package/dist/{server-Yk610niJ.js → server-BGbD7H5s.js} +2 -3
- package/dist/server.d.ts +6 -8
- package/dist/server.js +6 -6
- package/dist/{service-Bj-Mg63c.d.ts → service-CPiWPoiY.d.ts} +3 -7
- package/dist/{service-DA5BwfPQ.js → service-DUh2uGd2.js} +9 -11
- package/dist/{session-DUcEor2W.d.ts → session-CN4irEqf.d.ts} +3 -5
- package/dist/{session-X_g9dnU5.js → session-_1GY5gaG.js} +30 -18
- package/dist/{store-CsUNfC1w.d.ts → store-DvNTDNgn.d.ts} +2 -4
- package/dist/{table-names-B9LlRC0B.js → table-names-BIHjuEFK.js} +1 -2
- package/dist/testing.d.ts +2 -4
- package/dist/testing.js +3 -4
- package/dist/{tokens-DSbwkVSy.js → tokens-Bx4lZ0yt.js} +3 -6
- package/dist/{types-BLaYh0_f.d.ts → types-BX3vH18p.d.ts} +0 -2
- package/dist/{types-C35INXIs.d.ts → types-l6GOb_yc.d.ts} +2 -4
- package/dist/vite.d.ts +22 -22
- package/dist/vite.js +40 -45
- package/package.json +19 -19
|
@@ -1,63 +1,78 @@
|
|
|
1
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
1
|
+
import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
|
|
2
2
|
import { sql } from "drizzle-orm";
|
|
3
3
|
import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
|
|
4
|
-
|
|
4
|
+
// src/operations-core/database.ts
|
|
5
|
+
/**
|
|
6
|
+
* The thread, message, and counter tables of Comments under other names, for an app that keeps more than one set
|
|
7
|
+
* in one Database. Pass them to `installComments({ tables, tenant })`. Messages have no foreign key to their thread,
|
|
8
|
+
* because a thread is stored after its first message: delete the messages of a deleted thread with a trigger.
|
|
9
|
+
*/
|
|
10
|
+
function commentsSqliteTables(options) {
|
|
11
|
+
const { prefix, scope } = options;
|
|
12
|
+
const scopeColumn = () => scope ? text("scope").notNull().references(scope, { onDelete: "cascade" }) : text("scope").notNull();
|
|
13
|
+
return {
|
|
14
|
+
commentThreads: sqliteTable(`${prefix}_threads`, {
|
|
15
|
+
id: text("id").primaryKey(),
|
|
16
|
+
scope: scopeColumn(),
|
|
17
|
+
n: integer("n").notNull(),
|
|
18
|
+
subjectKind: text("subject_kind").notNull(),
|
|
19
|
+
subjectId: text("subject_id").notNull(),
|
|
20
|
+
anchor: text("anchor").notNull(),
|
|
21
|
+
status: text("status", { enum: ["open", "resolved"] }).notNull(),
|
|
22
|
+
resolvedBy: text("resolved_by"),
|
|
23
|
+
resolvedAt: integer("resolved_at"),
|
|
24
|
+
authorId: text("author_id").notNull(),
|
|
25
|
+
authorName: text("author_name"),
|
|
26
|
+
authorImage: text("author_image"),
|
|
27
|
+
actor: text("actor"),
|
|
28
|
+
/** JSON of the fields that app code keeps on the thread. */
|
|
29
|
+
metadata: text("metadata"),
|
|
30
|
+
/** JSON of the page, element, components, browser, and build that the overlay read. */
|
|
31
|
+
context: text("context"),
|
|
32
|
+
/** The version of the subject that the thread was started on. */
|
|
33
|
+
revision: integer("revision"),
|
|
34
|
+
/** The retry key of `comments.create`. Unique inside `scope`. */
|
|
35
|
+
requestId: text("request_id"),
|
|
36
|
+
createdAt: integer("created_at").notNull(),
|
|
37
|
+
updatedAt: integer("updated_at").notNull()
|
|
38
|
+
}, (table) => [
|
|
39
|
+
uniqueIndex(`${prefix}_threads_scope_n`).on(table.scope, table.n),
|
|
40
|
+
uniqueIndex(`${prefix}_threads_scope_request`).on(table.scope, table.requestId),
|
|
41
|
+
index(`${prefix}_threads_subject`).on(table.subjectKind, table.subjectId),
|
|
42
|
+
index(`${prefix}_threads_status`).on(table.status, table.updatedAt)
|
|
43
|
+
]),
|
|
44
|
+
commentMessages: sqliteTable(`${prefix}_messages`, {
|
|
45
|
+
id: text("id").primaryKey(),
|
|
46
|
+
threadId: text("thread_id").notNull(),
|
|
47
|
+
body: text("body").notNull(),
|
|
48
|
+
authorId: text("author_id").notNull(),
|
|
49
|
+
authorName: text("author_name"),
|
|
50
|
+
authorImage: text("author_image"),
|
|
51
|
+
actor: text("actor"),
|
|
52
|
+
mentions: text("mentions").notNull(),
|
|
53
|
+
attachments: text("attachments").notNull(),
|
|
54
|
+
createdAt: integer("created_at").notNull(),
|
|
55
|
+
editedAt: integer("edited_at")
|
|
56
|
+
}, (table) => [index(`${prefix}_messages_thread`).on(table.threadId, table.createdAt)]),
|
|
57
|
+
commentCounters: sqliteTable(`${prefix}_counters`, {
|
|
58
|
+
scope: (scope ? scopeColumn() : text("scope")).primaryKey(),
|
|
59
|
+
next: integer("next").notNull()
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const defaultTables = commentsSqliteTables({ prefix: "vitehub_comment" });
|
|
5
64
|
/**
|
|
6
65
|
* Threads of comments. `n` is unique inside `scope`, which is what `?comment=<n>` names. `anchor`, `actor`,
|
|
7
66
|
* `resolvedBy`, `metadata`, and `context` hold JSON. Times are milliseconds since the epoch.
|
|
8
67
|
*/
|
|
9
|
-
const commentThreads =
|
|
10
|
-
id: text("id").primaryKey(),
|
|
11
|
-
scope: text("scope").notNull(),
|
|
12
|
-
n: integer("n").notNull(),
|
|
13
|
-
subjectKind: text("subject_kind").notNull(),
|
|
14
|
-
subjectId: text("subject_id").notNull(),
|
|
15
|
-
anchor: text("anchor").notNull(),
|
|
16
|
-
status: text("status", { enum: ["open", "resolved"] }).notNull(),
|
|
17
|
-
resolvedBy: text("resolved_by"),
|
|
18
|
-
resolvedAt: integer("resolved_at"),
|
|
19
|
-
authorId: text("author_id").notNull(),
|
|
20
|
-
authorName: text("author_name"),
|
|
21
|
-
authorImage: text("author_image"),
|
|
22
|
-
actor: text("actor"),
|
|
23
|
-
/** JSON of the fields that app code keeps on the thread. */
|
|
24
|
-
metadata: text("metadata"),
|
|
25
|
-
/** JSON of the page, element, components, browser, and build that the overlay read. */
|
|
26
|
-
context: text("context"),
|
|
27
|
-
/** The version of the subject that the thread was started on. */
|
|
28
|
-
revision: integer("revision"),
|
|
29
|
-
/** The retry key of `comments.create`. Unique inside `scope`. */
|
|
30
|
-
requestId: text("request_id"),
|
|
31
|
-
createdAt: integer("created_at").notNull(),
|
|
32
|
-
updatedAt: integer("updated_at").notNull()
|
|
33
|
-
}, (table) => [
|
|
34
|
-
uniqueIndex("vitehub_comment_threads_scope_n").on(table.scope, table.n),
|
|
35
|
-
uniqueIndex("vitehub_comment_threads_scope_request").on(table.scope, table.requestId),
|
|
36
|
-
index("vitehub_comment_threads_subject").on(table.subjectKind, table.subjectId),
|
|
37
|
-
index("vitehub_comment_threads_status").on(table.status, table.updatedAt)
|
|
38
|
-
]);
|
|
68
|
+
const commentThreads = defaultTables.commentThreads;
|
|
39
69
|
/** One Markdown message. The first message of a thread is the comment. `mentions` and `attachments` hold JSON lists. */
|
|
40
|
-
const commentMessages =
|
|
41
|
-
id: text("id").primaryKey(),
|
|
42
|
-
threadId: text("thread_id").notNull(),
|
|
43
|
-
body: text("body").notNull(),
|
|
44
|
-
authorId: text("author_id").notNull(),
|
|
45
|
-
authorName: text("author_name"),
|
|
46
|
-
authorImage: text("author_image"),
|
|
47
|
-
actor: text("actor"),
|
|
48
|
-
mentions: text("mentions").notNull(),
|
|
49
|
-
attachments: text("attachments").notNull(),
|
|
50
|
-
createdAt: integer("created_at").notNull(),
|
|
51
|
-
editedAt: integer("edited_at")
|
|
52
|
-
}, (table) => [index("vitehub_comment_messages_thread").on(table.threadId, table.createdAt)]);
|
|
70
|
+
const commentMessages = defaultTables.commentMessages;
|
|
53
71
|
/**
|
|
54
72
|
* The next thread number of each scope. A number is handed out once, so a deleted thread never gives its number to a
|
|
55
73
|
* new one, and a link such as `?comment=3` keeps naming the same thread.
|
|
56
74
|
*/
|
|
57
|
-
const commentCounters =
|
|
58
|
-
scope: text("scope").primaryKey(),
|
|
59
|
-
next: integer("next").notNull()
|
|
60
|
-
});
|
|
75
|
+
const commentCounters = defaultTables.commentCounters;
|
|
61
76
|
/**
|
|
62
77
|
* The pull request comment of each message, when `defineComments({ forge })` posts threads. `id` is a message id,
|
|
63
78
|
* `summary:<repository>#<pull request>`, or `cleanup:<repository>#<remote id>` for a pending delete.
|
|
@@ -92,8 +107,7 @@ const commentsSchema = {
|
|
|
92
107
|
vitehubCommentCounters: commentCounters,
|
|
93
108
|
vitehubCommentForge: commentForge
|
|
94
109
|
};
|
|
95
|
-
|
|
96
|
-
//#region src/tables.ts
|
|
110
|
+
// src/tables.ts
|
|
97
111
|
/**
|
|
98
112
|
* The tables of `commentsSchema` as SQLite statements that are safe to run on every start. A database that Comments
|
|
99
113
|
* opens itself gets them on first use; a ViteHub Database gets the same tables from `vitehub database generate` instead.
|
|
@@ -113,8 +127,7 @@ const commentsTables = [
|
|
|
113
127
|
"CREATE INDEX IF NOT EXISTS `vitehub_comment_forge_thread` ON `vitehub_comment_forge` (`thread_id`)",
|
|
114
128
|
"CREATE INDEX IF NOT EXISTS `vitehub_comment_forge_pull_request` ON `vitehub_comment_forge` (`repository`,`pull_request`)"
|
|
115
129
|
];
|
|
116
|
-
|
|
117
|
-
//#region src/migrate.ts
|
|
130
|
+
// src/migrate.ts
|
|
118
131
|
/** The live-site threads, after the migration renames them. The migration never deletes them. */
|
|
119
132
|
const liveThreadsBackup = "vitehub_comment_threads_live";
|
|
120
133
|
/** The columns that one model added to `vitehub_comment_threads` after its first version. */
|
|
@@ -203,13 +216,14 @@ function runSqliteStatements(db, statements, start = 0) {
|
|
|
203
216
|
function names(rows) {
|
|
204
217
|
return (Array.isArray(rows) ? rows : Array.isArray(Reflect.get(Object(rows), "rows")) ? Reflect.get(Object(rows), "rows") : []).map((row) => String(Array.isArray(row) ? row[0] : Object.values(Object(row))[0]));
|
|
205
218
|
}
|
|
206
|
-
async function columns(db, postgres) {
|
|
207
|
-
|
|
208
|
-
return names(await db.
|
|
219
|
+
async function columns(db, postgres, table = "vitehub_comment_threads") {
|
|
220
|
+
const name = `'${table.replaceAll("'", "''")}'`;
|
|
221
|
+
if (postgres) return names(await db.execute(sql.raw(`SELECT column_name FROM information_schema.columns WHERE table_name = ${name} AND table_schema = current_schema()`)));
|
|
222
|
+
return names(await db.all(sql.raw(`SELECT name FROM pragma_table_info(${name})`)));
|
|
209
223
|
}
|
|
210
224
|
/** What the Database has: no comments yet, the live-site tables, one model without newer columns, or nothing to do. */
|
|
211
225
|
async function commentsSchemaState(db, options = {}) {
|
|
212
|
-
const found = await columns(db, options.dialect === "postgresql");
|
|
226
|
+
const found = await columns(db, options.dialect === "postgresql", options.table);
|
|
213
227
|
if (!found.length) return {
|
|
214
228
|
missing: [],
|
|
215
229
|
state: "empty"
|
|
@@ -285,8 +299,7 @@ function commentsSchemaGate(db, owner, options = {}) {
|
|
|
285
299
|
return ready;
|
|
286
300
|
};
|
|
287
301
|
}
|
|
288
|
-
|
|
289
|
-
//#region src/send/database.ts
|
|
302
|
+
// src/send/database.ts
|
|
290
303
|
/**
|
|
291
304
|
* One row for each send: the member, the threads it carried with the last message of each, and the read token. `threads`
|
|
292
305
|
* holds JSON, `[{ id, message, role }]`, and `sender` the member as Comments knew them when they sent. The token is
|
|
@@ -330,5 +343,4 @@ const commentSendsTables = [
|
|
|
330
343
|
"CREATE INDEX IF NOT EXISTS `vitehub_comment_sends_subject` ON `vitehub_comment_sends` (`subject_kind`,`subject_id`,`created_at`)",
|
|
331
344
|
"CREATE UNIQUE INDEX IF NOT EXISTS `vitehub_comment_sends_live_key` ON `vitehub_comment_sends` (`key`) WHERE `state` <> 'failed'"
|
|
332
345
|
];
|
|
333
|
-
|
|
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 };
|
|
346
|
+
export { commentsSchemaGate as a, migrateComments as c, commentForge as d, commentMessages as f, commentsSqliteTables as h, 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 };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/send/database.d.ts
|
|
2
1
|
/** Where a send is: delivered, read by the agent, answered, or not delivered. */
|
|
3
2
|
type CommentSendState = "pending" | "sent" | "working" | "done" | "failed";
|
|
4
3
|
/**
|
|
@@ -571,5 +570,4 @@ declare const commentSendsSchema: {
|
|
|
571
570
|
};
|
|
572
571
|
/** `commentSendsSchema` as SQLite statements that are safe to run on every start. */
|
|
573
572
|
declare const commentSendsTables: readonly string[];
|
|
574
|
-
//#endregion
|
|
575
573
|
export { commentSendsTables as i, commentSends as n, commentSendsSchema as r, CommentSendState as t };
|