@vite-hub/comments 0.8.0 → 0.9.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/dist/anchor.d.ts +2 -2
- package/dist/anchor.js +0 -1
- package/dist/{client-files-lC6X7XyS.js → client-files-CMPJEd21.js} +0 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -5
- package/dist/database.js +1 -1
- package/dist/{define-C-LUOouq.js → define-hs9Z38io.js} +0 -1
- package/dist/hosted/hosted-comments/frame.js +4 -4
- package/dist/hosted/hosted-comments/tools.js +59 -56
- package/dist/{index-d6NsDxu9.d.ts → index-CbXek64X.d.ts} +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -6
- package/dist/{install-BueV_fJY.js → install--HecUN5c.js} +2 -19
- package/dist/{install-F-_O7zDr.d.ts → install-C3CW6Vvw.d.ts} +4 -4
- package/dist/{migrate-oseJAYbm.js → migrate-cxoJK4JQ.js} +0 -18
- package/dist/{operations-jaihyWw2.d.ts → operations-D0EO1pzL.d.ts} +3 -7
- package/dist/{operations-0llC5kKO.js → operations-DHXmbtb3.js} +3 -30
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/overlay/client-BszZKIf8.js +4 -0
- package/dist/overlay/overlay.js +38 -35
- package/dist/page/loader.js +14 -11
- package/dist/{page-CDhmXO-y.js → page-CJz1K67L.js} +1 -1
- package/dist/{page-BgvzzsJb.d.ts → page-DRM1j84-.d.ts} +1 -1
- package/dist/{path-8yqMd8zR.js → path-sv8kjq3i.js} +0 -4
- package/dist/{plugin-DGUqlc3C.js → plugin-DczA2K-y.js} +3 -3
- package/dist/realtime.d.ts +5 -5
- package/dist/realtime.js +2 -2
- package/dist/{rpc-kkxzQ3Qy.js → rpc-51X1TWKb.js} +1 -1
- package/dist/{rpc-D-eqtyfh.d.ts → rpc-DZB3yU0z.d.ts} +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +1 -1
- package/dist/runtime/auth.d.ts +1 -1
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/index.d.ts +6 -6
- package/dist/runtime/index.js +8 -30
- package/dist/server.d.ts +7 -7
- package/dist/server.js +6 -6
- package/dist/{service-DaMq8TBw.js → service-DFMwCr60.js} +2 -12
- package/dist/{service-CMVA_Ryv.d.ts → service-qaMuJ7UX.d.ts} +2 -2
- package/dist/{session-B7GDrqsK.js → session-1SI3_wLJ.js} +11 -30
- package/dist/{session-EzQqBeE8.d.ts → session-CK3Rnjto.d.ts} +2 -2
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +0 -1
- package/dist/{tokens-Bx4lZ0yt.js → tokens-WRh__ppm.js} +0 -1
- package/dist/{types-BX3vH18p.d.ts → types-BmzTyGt-.d.ts} +4 -0
- package/dist/{types-qzJKgWYS.d.ts → types-VSVs4jIw.d.ts} +1 -1
- package/dist/vite.d.ts +3 -3
- package/dist/vite.js +2 -33
- package/package.json +7 -7
- package/dist/overlay/client-ZBsUybIe.js +0 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as CommentUser, T as CommentThread, n as CommentActor, s as CommentContext, w as CommentSubject, y as CommentMessage } from "./types-
|
|
2
|
-
import { D as CommentsPolicyGate, c as CreateCommentThreadInput, d as FindCommentThreadInput, f as ListCommentThreadsOptions, h as CommentAction, j as CommentsUser, l as DefineCommentsOptions, m as ReplyOptions, p as ReplyInput, t as CommentsErrorCode, u as EditCommentInput } from "./types-
|
|
1
|
+
import { D as CommentUser, T as CommentThread, n as CommentActor, s as CommentContext, w as CommentSubject, y as CommentMessage } from "./types-BmzTyGt-.js";
|
|
2
|
+
import { D as CommentsPolicyGate, c as CreateCommentThreadInput, d as FindCommentThreadInput, f as ListCommentThreadsOptions, h as CommentAction, j as CommentsUser, l as DefineCommentsOptions, m as ReplyOptions, p as ReplyInput, t as CommentsErrorCode, u as EditCommentInput } from "./types-VSVs4jIw.js";
|
|
3
3
|
import { Result } from "@vite-hub/runtime";
|
|
4
4
|
/**
|
|
5
5
|
* The context of a thread as label and value pairs, in the order a person reads them: page, element, components,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as ElementAnchor, C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, M as PageAnchor, N as TextAnchor, O as CommentUsersInput, S as CommentStatus, T as CommentThread, _ as CommentListCursor, a as CommentBuild, b as CommentMetadata, c as CommentCreateInput, d as CommentDeliveryError, f as CommentEditInput, g as CommentGetInput, h as CommentForgeLink, i as CommentAttachment, j as ImageAnchor, k as CommentsTransport, l as CommentDeleteInput, m as CommentFiles, n as CommentActor, o as CommentComponent, p as CommentEvent, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentDelivery, v as CommentListQuery, w as CommentSubject, x as CommentReplyInput, y as CommentMessage } from "./types-
|
|
2
|
-
import { A as CommentsStoreAttachmentContext, C as CommentsDefinition, D as CommentsPolicyGate, E as CommentsPeopleSearchContext, M as commentsRoleAllows, N as defaultPolicy, O as CommentsRateLimit, P as defineCommentSubject, S as CommentsCanMentionContext, T as CommentsPeople, _ as CommentMessageEvent, a as CommentsPageContext, b as CommentsAuthorize, c as CreateCommentThreadInput, d as FindCommentThreadInput, f as ListCommentThreadsOptions, g as CommentMentionEvent, h as CommentAction, i as CommentsIdentifyContext, j as CommentsUser, k as CommentsReadAttachmentContext, l as DefineCommentsOptions, m as ReplyOptions, n as CommentsForgeOptions, o as CommentsPageSubject, p as ReplyInput, r as CommentsForgeTarget, s as CommentsRequestEvent, t as CommentsErrorCode, u as EditCommentInput, v as CommentSubjectDefinition, w as CommentsGitHubAccess, x as CommentsAuthorizeContext, y as CommentsAttachmentFile } from "./types-
|
|
3
|
-
import { n as defineComments, r as describeCommentContext, t as Comments } from "./index-
|
|
4
|
-
import { c as normalizeCommentPage, t as commentRoom } from "./page-
|
|
1
|
+
import { A as ElementAnchor, C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, M as PageAnchor, N as TextAnchor, O as CommentUsersInput, S as CommentStatus, T as CommentThread, _ as CommentListCursor, a as CommentBuild, b as CommentMetadata, c as CommentCreateInput, d as CommentDeliveryError, f as CommentEditInput, g as CommentGetInput, h as CommentForgeLink, i as CommentAttachment, j as ImageAnchor, k as CommentsTransport, l as CommentDeleteInput, m as CommentFiles, n as CommentActor, o as CommentComponent, p as CommentEvent, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentDelivery, v as CommentListQuery, w as CommentSubject, x as CommentReplyInput, y as CommentMessage } from "./types-BmzTyGt-.js";
|
|
2
|
+
import { A as CommentsStoreAttachmentContext, C as CommentsDefinition, D as CommentsPolicyGate, E as CommentsPeopleSearchContext, M as commentsRoleAllows, N as defaultPolicy, O as CommentsRateLimit, P as defineCommentSubject, S as CommentsCanMentionContext, T as CommentsPeople, _ as CommentMessageEvent, a as CommentsPageContext, b as CommentsAuthorize, c as CreateCommentThreadInput, d as FindCommentThreadInput, f as ListCommentThreadsOptions, g as CommentMentionEvent, h as CommentAction, i as CommentsIdentifyContext, j as CommentsUser, k as CommentsReadAttachmentContext, l as DefineCommentsOptions, m as ReplyOptions, n as CommentsForgeOptions, o as CommentsPageSubject, p as ReplyInput, r as CommentsForgeTarget, s as CommentsRequestEvent, t as CommentsErrorCode, u as EditCommentInput, v as CommentSubjectDefinition, w as CommentsGitHubAccess, x as CommentsAuthorizeContext, y as CommentsAttachmentFile } from "./types-VSVs4jIw.js";
|
|
3
|
+
import { n as defineComments, r as describeCommentContext, t as Comments } from "./index-CbXek64X.js";
|
|
4
|
+
import { c as normalizeCommentPage, t as commentRoom } from "./page-DRM1j84-.js";
|
|
5
5
|
export { type AreaAnchor, type CommentAction, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentDelivery, type CommentDeliveryError, type CommentEditInput, type CommentEvent, type CommentFiles, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMentionEvent, type CommentMessage, type CommentMessageEvent, type CommentMetadata, type CommentReplyInput, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentSubjectDefinition, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, Comments, type CommentsAttachmentFile, type CommentsAuthorize, type CommentsAuthorizeContext, type CommentsCanMentionContext, type CommentsDefinition, type CommentsErrorCode, type CommentsForgeOptions, type CommentsForgeTarget, type CommentsGitHubAccess, type CommentsIdentifyContext, type CommentsPageContext, type CommentsPageSubject, type CommentsPeople, type CommentsPeopleSearchContext, type CommentsPolicyGate, type CommentsRateLimit, type CommentsReadAttachmentContext, type CommentsRequestEvent, type CommentsStoreAttachmentContext, type CommentsTransport, type CommentsUser, type CreateCommentThreadInput, type DefineCommentsOptions, type EditCommentInput, type ElementAnchor, type FindCommentThreadInput, type ImageAnchor, type ListCommentThreadsOptions, type PageAnchor, type ReplyInput, type ReplyOptions, type TextAnchor, commentRoom, commentsRoleAllows, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage };
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import { C as threadChanged, S as suggest, T as clientRateLimitIssue, a as createThread, b as scopeOf, c as earlierThread, g as replyToThread, l as editMessage, r as can, s as earlierReply } from "./service-
|
|
2
|
-
import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition } from "./define-
|
|
1
|
+
import { C as threadChanged, S as suggest, T as clientRateLimitIssue, a as createThread, b as scopeOf, c as earlierThread, g as replyToThread, l as editMessage, r as can, s as earlierReply } from "./service-DFMwCr60.js";
|
|
2
|
+
import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition } from "./define-hs9Z38io.js";
|
|
3
3
|
import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.js";
|
|
4
4
|
import { t as commentsErrors } from "./errors-C5utwZ5H.js";
|
|
5
5
|
import { a as runtimes, i as runtimeOf, t as pendingKey } from "./installed-BqQKo6WC.js";
|
|
6
|
-
import { n as commentRoom, p as normalizeCommentPage } from "./page-
|
|
6
|
+
import { n as commentRoom, p as normalizeCommentPage } from "./page-CJz1K67L.js";
|
|
7
7
|
import { t as describeCommentContext } from "./context-DbkBjITZ.js";
|
|
8
8
|
// src/index.ts
|
|
9
|
-
/** A thread that someone deleted during the change: the store reads it again and finds nothing. */
|
|
10
9
|
function gone(error) {
|
|
11
10
|
if (error instanceof Error && Reflect.get(error, "code") === "COMMENTS_R0002") return void 0;
|
|
12
11
|
throw error;
|
|
13
12
|
}
|
|
14
|
-
/** Diagnostics of the shared core, as the `[error, data]` codes of the server API. */
|
|
15
13
|
function resultError(error, id) {
|
|
16
14
|
const code = error instanceof Error ? Reflect.get(error, "code") : void 0;
|
|
17
15
|
if (code === "COMMENTS_R0002" || code === "COMMENTS_R0003") return commentsErrors.COMMENTS_NOT_FOUND({ id });
|
|
18
16
|
if (code === "COMMENTS_R0016") return commentsErrors.COMMENTS_RESOLVED();
|
|
19
17
|
return invalidInput(error);
|
|
20
18
|
}
|
|
21
|
-
/** A diagnostic of the shared core about the input, as `COMMENTS_INVALID_INPUT`. Any other error is thrown again. */
|
|
22
19
|
function invalidInput(error) {
|
|
23
20
|
const code = error instanceof Error ? Reflect.get(error, "code") : void 0;
|
|
24
21
|
if (typeof code === "string" && [
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { i as installCommentsRuntime } from "./server-CAMs6viR.js";
|
|
2
2
|
import { r as guestIdPrefix } from "./identity-CT7-UGmS.js";
|
|
3
3
|
import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.js";
|
|
4
|
-
import { c as commentForge, d as commentsSchema, l as commentMessages, n as commentsSchemaGate, s as commentCounters, u as commentThreads } from "./migrate-
|
|
4
|
+
import { c as commentForge, d as commentsSchema, l as commentMessages, n as commentsSchemaGate, s as commentCounters, u as commentThreads } from "./migrate-cxoJK4JQ.js";
|
|
5
5
|
import { t as logFailure } from "./request-log-DllKQXj7.js";
|
|
6
|
-
import { i as getActiveCloudflareBinding, n as recentGitHubToken } from "./tokens-
|
|
6
|
+
import { i as getActiveCloudflareBinding, n as recentGitHubToken } from "./tokens-WRh__ppm.js";
|
|
7
7
|
import { t as describeCommentContext } from "./context-DbkBjITZ.js";
|
|
8
8
|
import { a as runtimes, t as pendingKey } from "./installed-BqQKo6WC.js";
|
|
9
9
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
@@ -69,7 +69,6 @@ function groupMessages(byThread, rows) {
|
|
|
69
69
|
else byThread.set(row.threadId, [message]);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
/** `resolved_by` keeps the person, with the agent that acted for them as `actor`. Rows from before it hold the person alone. */
|
|
73
72
|
function resolver(json) {
|
|
74
73
|
const found = parseJson(json, void 0);
|
|
75
74
|
if (!found) return {};
|
|
@@ -112,11 +111,6 @@ const uniqueCodes = /* @__PURE__ */ new Set([
|
|
|
112
111
|
"SQLITE_CONSTRAINT_UNIQUE"
|
|
113
112
|
]);
|
|
114
113
|
const uniqueMessage = /UNIQUE constraint failed|duplicate key value violates unique constraint/i;
|
|
115
|
-
/**
|
|
116
|
-
* A unique index refused the insert. Drizzle wraps the driver error in one whose message carries the statement and its
|
|
117
|
-
* parameters, which come from the user. So only codes decide, and a message counts only when it is the driver's own:
|
|
118
|
-
* the error with no cause below it.
|
|
119
|
-
*/
|
|
120
114
|
function isUniqueViolation(error) {
|
|
121
115
|
for (let current = error, depth = 0; current && depth < 5; depth++) {
|
|
122
116
|
const code = Reflect.get(Object(current), "code");
|
|
@@ -609,7 +603,6 @@ const commentListResponse = v.array(v.object({
|
|
|
609
603
|
body: v.string()
|
|
610
604
|
}));
|
|
611
605
|
const pullsResponse = v.array(v.object({ number: v.number() }));
|
|
612
|
-
/** A Server Env value from the active Cloudflare bindings, else from `process.env`. */
|
|
613
606
|
function serverEnv(name) {
|
|
614
607
|
return getActiveCloudflareBinding(name) ?? globalThis.process?.env?.[name];
|
|
615
608
|
}
|
|
@@ -753,26 +746,21 @@ function commentMarker(threadId, commentId) {
|
|
|
753
746
|
function unlinked(text) {
|
|
754
747
|
return text.replace(/@(?=[\w-])/g, "@").replace(/#(?=\d)/g, "#");
|
|
755
748
|
}
|
|
756
|
-
/** A thread number as people say it, "#3", that GitHub does not link to issue 3. */
|
|
757
749
|
function number(thread) {
|
|
758
750
|
return `#\u2060${thread.n}`;
|
|
759
751
|
}
|
|
760
752
|
function quote(text) {
|
|
761
753
|
return text.split("\n").map((line) => `> ${line}`).join("\n");
|
|
762
754
|
}
|
|
763
|
-
/** Comment text is plain text in the preview; keep it literal in GitHub Markdown too. */
|
|
764
755
|
function plainText(text) {
|
|
765
756
|
return unlinked(text).replace(/&/g, "&").replace(/[\\`*_{}[\]<>#+=!:|~-]/g, "\\$&").replace(/\b(www)\./gi, "$1\\.").replace(/^(\s*\d+)([.)])(?=\s)/gm, "$1\\$2").replace(/^[ \t]/gm, (char) => char === " " ? "	" : " ");
|
|
766
757
|
}
|
|
767
|
-
/** One line for a Markdown table cell. */
|
|
768
758
|
function cell(text) {
|
|
769
759
|
return plainText(text).replace(/\s+/g, " ").trim();
|
|
770
760
|
}
|
|
771
|
-
/** A code span for a Markdown table cell. GitHub shows `<` in a code span as typed, so only pipes are escaped. */
|
|
772
761
|
function code(text) {
|
|
773
762
|
return `\`${text.replace(/\s+/g, " ").replace(/\|/g, "\\|").replace(/`/g, "'").trim()}\``;
|
|
774
763
|
}
|
|
775
|
-
/** The first sentence of a comment, at most 100 characters. */
|
|
776
764
|
function headline(body) {
|
|
777
765
|
const first = body.trim().split(/(?<=[.!?])\s/, 1)[0] ?? "";
|
|
778
766
|
return first.length > 100 ? `${first.slice(0, 99).trimEnd()}…` : first;
|
|
@@ -780,7 +768,6 @@ function headline(body) {
|
|
|
780
768
|
function authorName(comment) {
|
|
781
769
|
return unlinked(`${comment.author.name ?? comment.author.id}${comment.author.guest ? " (guest)" : ""}`);
|
|
782
770
|
}
|
|
783
|
-
/** The page of a thread: the subject of a page thread. */
|
|
784
771
|
function pageOf(thread) {
|
|
785
772
|
return thread.subject.id;
|
|
786
773
|
}
|
|
@@ -873,9 +860,7 @@ function renderSummary(input) {
|
|
|
873
860
|
].join("\n");
|
|
874
861
|
}
|
|
875
862
|
// src/forge/sync.ts
|
|
876
|
-
/** How long a row that is being posted stays claimed, so a sync that died does not block the comment for good. */
|
|
877
863
|
const claimTimeout = 6e4;
|
|
878
|
-
/** Change detection only: two FNV-1a passes, as `commentRoom()` hashes pages. */
|
|
879
864
|
function digest(text) {
|
|
880
865
|
let a = 2166136261;
|
|
881
866
|
let b = 1523705862;
|
|
@@ -925,7 +910,6 @@ function authorizationFailed(error) {
|
|
|
925
910
|
const status = gitHubFailureStatus(error);
|
|
926
911
|
return status === 401 || status === 403 || status === 404;
|
|
927
912
|
}
|
|
928
|
-
/** Runs tasks with the same key one after another, so two syncs of a thread or a pull request never interleave. */
|
|
929
913
|
function serial() {
|
|
930
914
|
const tails = /* @__PURE__ */ new Map();
|
|
931
915
|
return (key, task) => {
|
|
@@ -1281,7 +1265,6 @@ function createForgeSync(options, input) {
|
|
|
1281
1265
|
}
|
|
1282
1266
|
// src/install.ts
|
|
1283
1267
|
var install_exports = /* @__PURE__ */ __exportAll({ installComments: () => installComments });
|
|
1284
|
-
/** The store, after the tables are ready: each method waits for `ready` first. */
|
|
1285
1268
|
function gated(store, ready) {
|
|
1286
1269
|
const wrapped = {};
|
|
1287
1270
|
for (const key of Object.keys(store)) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { T as CommentThread } from "./types-
|
|
1
|
+
import { T as CommentThread } from "./types-BmzTyGt-.js";
|
|
2
2
|
import { o as commentsSchema } from "./database-DUs3c2al.js";
|
|
3
|
-
import { c as CommentsTables, i as CommentsRuntime, n as CommentsAttachmentStore, o as CommentsDatabase, u as SharedRateLimit } from "./service-
|
|
4
|
-
import { t as Comments } from "./index-
|
|
5
|
-
import { T as CommentsPeople } from "./types-
|
|
3
|
+
import { c as CommentsTables, i as CommentsRuntime, n as CommentsAttachmentStore, o as CommentsDatabase, u as SharedRateLimit } from "./service-qaMuJ7UX.js";
|
|
4
|
+
import { t as Comments } from "./index-CbXek64X.js";
|
|
5
|
+
import { T as CommentsPeople } from "./types-VSVs4jIw.js";
|
|
6
6
|
import { r as CommentsSchemaOwner } from "./migrate-XjFeQppf.js";
|
|
7
7
|
/** Options of `tenantCommentsStore()`. */
|
|
8
8
|
interface TenantCommentsStoreOptions {
|
|
@@ -25,13 +25,9 @@ function commentsSqliteTables(options) {
|
|
|
25
25
|
authorName: text("author_name"),
|
|
26
26
|
authorImage: text("author_image"),
|
|
27
27
|
actor: text("actor"),
|
|
28
|
-
/** JSON of the fields that app code keeps on the thread. */
|
|
29
28
|
metadata: text("metadata"),
|
|
30
|
-
/** JSON of the page, element, components, browser, and build that the overlay read. */
|
|
31
29
|
context: text("context"),
|
|
32
|
-
/** The version of the subject that the thread was started on. */
|
|
33
30
|
revision: integer("revision"),
|
|
34
|
-
/** The retry key of `comments.create`. Unique inside `scope`. */
|
|
35
31
|
requestId: text("request_id"),
|
|
36
32
|
createdAt: integer("created_at").notNull(),
|
|
37
33
|
updatedAt: integer("updated_at").notNull()
|
|
@@ -79,19 +75,14 @@ const commentCounters = defaultTables.commentCounters;
|
|
|
79
75
|
*/
|
|
80
76
|
const commentForge = sqliteTable("vitehub_comment_forge", {
|
|
81
77
|
id: text("id").primaryKey(),
|
|
82
|
-
/** Null for summaries and cleanup rows, which survive deletion of the original thread. */
|
|
83
78
|
threadId: text("thread_id"),
|
|
84
79
|
repository: text("repository").notNull(),
|
|
85
80
|
pullRequest: integer("pull_request").notNull(),
|
|
86
|
-
/** The forge's id of the comment. Null until it posts. */
|
|
87
81
|
remoteId: text("remote_id"),
|
|
88
|
-
/** The GraphQL id, to hide the comment of a resolved thread. */
|
|
89
82
|
nodeId: text("node_id"),
|
|
90
83
|
url: text("url"),
|
|
91
|
-
/** Hash of the body the forge has, so an unchanged comment is not sent again. */
|
|
92
84
|
digest: text("digest"),
|
|
93
85
|
postedAs: text("posted_as", { enum: ["author", "app"] }),
|
|
94
|
-
/** Whether the forge hides the comment, because its thread is resolved. */
|
|
95
86
|
minimized: integer("minimized", { mode: "boolean" }).notNull().default(false),
|
|
96
87
|
error: text("error"),
|
|
97
88
|
updatedAt: integer("updated_at").notNull()
|
|
@@ -130,25 +121,18 @@ const commentsTables = [
|
|
|
130
121
|
// src/migrate.ts
|
|
131
122
|
/** The live-site threads, after the migration renames them. The migration never deletes them. */
|
|
132
123
|
const liveThreadsBackup = "vitehub_comment_threads_live";
|
|
133
|
-
/** The columns that one model added to `vitehub_comment_threads` after its first version. */
|
|
134
124
|
const addedColumns = {
|
|
135
125
|
metadata: "text",
|
|
136
126
|
context: "text",
|
|
137
127
|
revision: "integer",
|
|
138
128
|
request_id: "text"
|
|
139
129
|
};
|
|
140
|
-
/** The unique index of the `comments.create` retry key, which came with `request_id`. */
|
|
141
130
|
const requestIndex = commentsTables.find((statement) => statement.includes("`vitehub_comment_threads_scope_request`"));
|
|
142
131
|
const scopeOf = "CASE WHEN `scope` = 'pages' THEN 'site' ELSE `scope` END";
|
|
143
132
|
function migratedAuthorId(column) {
|
|
144
133
|
const id = `json_extract(${column}, '$.id')`;
|
|
145
134
|
return `CASE WHEN json_extract(${column}, '$.guest') = 1 AND substr(${id}, 1, 6) <> 'guest:' THEN 'guest:' || ${id} ELSE ${id} END`;
|
|
146
135
|
}
|
|
147
|
-
/**
|
|
148
|
-
* Moves the live-site tables to the tables of one model, on SQLite, libSQL, and D1. It renames the threads table to
|
|
149
|
-
* `vitehub_comment_threads_live`, creates the new tables, and copies every thread and comment. It deletes nothing:
|
|
150
|
-
* `vitehub_comment_threads_live`, `vitehub_comments`, and `vitehub_comment_scope_counters` stay for you to check.
|
|
151
|
-
*/
|
|
152
136
|
function liveToCurrent() {
|
|
153
137
|
const subjectKind = "CASE WHEN `scope` = 'pages' THEN 'page' WHEN instr(`scope`, ':') > 1 THEN substr(`scope`, 1, instr(`scope`, ':') - 1) ELSE `scope` END";
|
|
154
138
|
const subjectId = "CASE WHEN `scope` = 'pages' THEN `page` WHEN instr(`scope`, ':') > 1 THEN substr(`scope`, instr(`scope`, ':') + 1) ELSE `page` END";
|
|
@@ -205,14 +189,12 @@ function commentsMigrationSql(options) {
|
|
|
205
189
|
...commentsTables.filter((statement) => statement.includes("vitehub_comment_forge"))
|
|
206
190
|
];
|
|
207
191
|
}
|
|
208
|
-
/** Keep synchronous transaction callbacks synchronous, so their driver can roll back a later failure. */
|
|
209
192
|
function runSqliteStatements(db, statements, start = 0) {
|
|
210
193
|
for (let index = start; index < statements.length; index++) {
|
|
211
194
|
const result = db.run(sql.raw(statements[index]));
|
|
212
195
|
if (typeof result === "object" && result !== null && "then" in result && typeof result.then === "function") return Promise.resolve(result).then(() => runSqliteStatements(db, statements, index + 1));
|
|
213
196
|
}
|
|
214
197
|
}
|
|
215
|
-
/** The first column of each row: libSQL and D1 return objects, the SQLite proxy returns arrays. */
|
|
216
198
|
function names(rows) {
|
|
217
199
|
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]));
|
|
218
200
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-
|
|
1
|
+
import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-qaMuJ7UX.js";
|
|
2
2
|
import { t as AnyOperation } from "./operations-DFLer1fR.js";
|
|
3
|
-
import { D as CommentsPolicyGate, j as CommentsUser } from "./types-
|
|
4
|
-
import { C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, O as CommentUsersInput, T as CommentThread, c as CommentCreateInput, f as CommentEditInput, g as CommentGetInput, i as CommentAttachment, l as CommentDeleteInput, n as CommentActor, s as CommentContext, v as CommentListQuery, x as CommentReplyInput, y as CommentMessage } from "./types-
|
|
3
|
+
import { D as CommentsPolicyGate, j as CommentsUser } from "./types-VSVs4jIw.js";
|
|
4
|
+
import { C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, O as CommentUsersInput, T as CommentThread, c as CommentCreateInput, f as CommentEditInput, g as CommentGetInput, i as CommentAttachment, l as CommentDeleteInput, n as CommentActor, s as CommentContext, v as CommentListQuery, x as CommentReplyInput, y as CommentMessage } from "./types-BmzTyGt-.js";
|
|
5
5
|
import * as v from "valibot";
|
|
6
6
|
/** The fields of a thread in a list, as JSON. */
|
|
7
7
|
interface CommentThreadSummary {
|
|
@@ -259,11 +259,9 @@ declare const commentActions: {
|
|
|
259
259
|
threads(input: v.InferOutput<typeof threadsInput>, who: CommentsCaller): Promise<CommentThreadsPage>;
|
|
260
260
|
list(input: CommentListQuery, who: CommentsCaller): Promise<CommentThread[]>;
|
|
261
261
|
get(input: CommentGetInput, who: CommentsCaller): Promise<CommentThread | null>;
|
|
262
|
-
/** `context` is the page context that the overlay read and its transport checked. */
|
|
263
262
|
create(input: CommentCreateInput & {
|
|
264
263
|
context?: CommentContext;
|
|
265
264
|
}, who: CommentsCaller): Promise<CommentThread>;
|
|
266
|
-
/** `allowResolved`: the operations keep a reply box on resolved threads, and a reply keeps the thread resolved. */
|
|
267
265
|
reply(input: CommentReplyInput, who: CommentsCaller, options?: {
|
|
268
266
|
allowResolved?: boolean;
|
|
269
267
|
}): Promise<{
|
|
@@ -277,12 +275,10 @@ declare const commentActions: {
|
|
|
277
275
|
threadId: string;
|
|
278
276
|
reply?: string;
|
|
279
277
|
}[], who: CommentsCaller): Promise<CommentThread[]>;
|
|
280
|
-
/** `minimum`: the shortest query that gets suggestions. The operations ask for two characters. */
|
|
281
278
|
users(input: CommentUsersInput, who: CommentsCaller, options?: {
|
|
282
279
|
minimum?: number;
|
|
283
280
|
}): Promise<CommentUser[]>;
|
|
284
281
|
upload(input: CommentUploadInput, who: CommentsCaller): Promise<CommentAttachment>;
|
|
285
|
-
/** The file of an attachment key, for a caller who may read a thread whose messages list it. */
|
|
286
282
|
attachment(input: {
|
|
287
283
|
key: string;
|
|
288
284
|
}, who: CommentsCaller): Promise<CommentsAttachmentBody>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as outboxAccountHeader } from "./client-files-
|
|
2
|
-
import { n as pagePathOf, t as isPagePath } from "./path-
|
|
1
|
+
import { n as outboxAccountHeader } from "./client-files-CMPJEd21.js";
|
|
2
|
+
import { n as pagePathOf, t as isPagePath } from "./path-sv8kjq3i.js";
|
|
3
3
|
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
4
4
|
import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.js";
|
|
5
|
-
import { C as threadChanged, E as createClientRateLimit, S as suggest, _ as requestIdSchema, a as createThread, c as earlierThread, d as maximumAttachmentBytes, f as maximumCommentBodyLength, g as replyToThread, h as readAttachment, l as editMessage, m as personOf, n as base64, o as deniedError, r as can, s as earlierReply, t as attachmentThread, u as fail, v as retried, w as clientAddressKey, x as storeAttachment, y as retriedReply } from "./service-
|
|
5
|
+
import { C as threadChanged, E as createClientRateLimit, S as suggest, _ as requestIdSchema, a as createThread, c as earlierThread, d as maximumAttachmentBytes, f as maximumCommentBodyLength, g as replyToThread, h as readAttachment, l as editMessage, m as personOf, n as base64, o as deniedError, r as can, s as earlierReply, t as attachmentThread, u as fail, v as retried, w as clientAddressKey, x as storeAttachment, y as retriedReply } from "./service-DFMwCr60.js";
|
|
6
6
|
import { n as guestFromHeaders, t as authorOf } from "./identity-CT7-UGmS.js";
|
|
7
7
|
import { t as describeCommentContext } from "./context-DbkBjITZ.js";
|
|
8
8
|
import { t as commentsRuntime } from "./server-CAMs6viR.js";
|
|
@@ -437,9 +437,7 @@ function operationAccessAllows(access, section, call) {
|
|
|
437
437
|
function commentPersonName(person) {
|
|
438
438
|
return `${person.name ?? person.id}${person.guest ? " (guest)" : ""}`;
|
|
439
439
|
}
|
|
440
|
-
/** Thousandths of an element box as a percentage, such as `97.3%`. */
|
|
441
440
|
const share = (value) => `${Number((value / 10).toFixed(1))}%`;
|
|
442
|
-
/** What the comment points at, in words: the element, the quoted text, or the part of the element box it marked. */
|
|
443
441
|
function describeAnchor(anchor) {
|
|
444
442
|
switch (anchor.kind) {
|
|
445
443
|
case "page": return "Anchor: the whole page";
|
|
@@ -461,7 +459,6 @@ function describeCommentThread(thread) {
|
|
|
461
459
|
if (thread.resolvedBy) lines.push("", `Resolved by ${thread.resolvedActor ? `${thread.resolvedActor.name ?? thread.resolvedActor.id} for ` : ""}${commentPersonName(thread.resolvedBy)} at ${new Date(thread.resolvedAt ?? thread.updatedAt).toISOString()}`);
|
|
462
460
|
return lines.join("\n");
|
|
463
461
|
}
|
|
464
|
-
/** At most `max` characters of `value`, flattened to one line and cut at a word, with `…` when cut. */
|
|
465
462
|
function clip(value, max) {
|
|
466
463
|
const flat = value.replace(/\s+/g, " ").trim();
|
|
467
464
|
if (flat.length <= max) return flat;
|
|
@@ -493,7 +490,6 @@ function commentThreadSummary(thread) {
|
|
|
493
490
|
updatedAt: thread.updatedAt
|
|
494
491
|
};
|
|
495
492
|
}
|
|
496
|
-
/** A time to the minute in UTC, in ISO 8601, such as `2026-11-17T09:22Z`. */
|
|
497
493
|
function minute(time) {
|
|
498
494
|
return `${new Date(time).toISOString().slice(0, 16)}Z`;
|
|
499
495
|
}
|
|
@@ -526,7 +522,6 @@ const defaultLimit = 200;
|
|
|
526
522
|
const maximumLimit = 500;
|
|
527
523
|
const maximumSuggestions = 10;
|
|
528
524
|
const minimumQuery = 2;
|
|
529
|
-
/** Threads that `authorize` checks at once. */
|
|
530
525
|
const authorizeConcurrency = 16;
|
|
531
526
|
const thousandths = v.pipe(v.number(), v.minValue(0), v.maxValue(1e3));
|
|
532
527
|
const selector = v.pipe(v.string(), v.minLength(1), v.maxLength(2048));
|
|
@@ -611,12 +606,6 @@ function actorOf(actor) {
|
|
|
611
606
|
...actor.label ? { name: actor.label } : {}
|
|
612
607
|
} : void 0;
|
|
613
608
|
}
|
|
614
|
-
/**
|
|
615
|
-
* Operations run only after the Console admitted the call to the `comments` section, so `authorize` gets
|
|
616
|
-
* `console: true`. With `identify`, the app names the user from the request of the call, as in the overlay API, and
|
|
617
|
-
* `authorize` decides; a call without a request, such as an agent's, has no user. Without `identify`, the user is the
|
|
618
|
-
* Console's, and the default policy trusts it.
|
|
619
|
-
*/
|
|
620
609
|
async function caller(context) {
|
|
621
610
|
const runtime = await commentsRuntime();
|
|
622
611
|
const actor = actorOf(context.actor);
|
|
@@ -639,7 +628,6 @@ async function caller(context) {
|
|
|
639
628
|
...context.waitUntil ? { waitUntil: context.waitUntil } : {}
|
|
640
629
|
};
|
|
641
630
|
}
|
|
642
|
-
/** Asks the policy, with the thread and its subject, or the subject a thread would start on. */
|
|
643
631
|
async function permitted(who, action, target = {}) {
|
|
644
632
|
return can(who.runtime, {
|
|
645
633
|
action,
|
|
@@ -652,7 +640,6 @@ async function permitted(who, action, target = {}) {
|
|
|
652
640
|
async function allow(who, action, target) {
|
|
653
641
|
if (!await permitted(who, action, target)) throw deniedError(who.runtime, action, who.user, who.gate);
|
|
654
642
|
}
|
|
655
|
-
/** The signed-in user, else the guest of the request, which only a policy that lets anonymous people write gets this far. */
|
|
656
643
|
function author(who) {
|
|
657
644
|
if (who.user) return personOf(authorOf(who.user));
|
|
658
645
|
const guest = who.request ? guestFromHeaders(who.request.headers) : void 0;
|
|
@@ -664,10 +651,6 @@ function checkOutboxAccount(who) {
|
|
|
664
651
|
if (expected != null && expected !== encodeURIComponent(author(who).id)) throw fail(commentsErrorDiagnostics.COMMENTS_OUTBOX_ACCOUNT_CHANGED(), 401);
|
|
665
652
|
}
|
|
666
653
|
const guestLimits = /* @__PURE__ */ new WeakMap();
|
|
667
|
-
/**
|
|
668
|
-
* Counts one write of a guest against `defineComments({ rateLimit })`, by the address of the request. Signed-in people
|
|
669
|
-
* and Agents are not limited. Call it after the policy allowed the write, so a refused write uses no budget.
|
|
670
|
-
*/
|
|
671
654
|
async function limitGuest(who) {
|
|
672
655
|
const policy = who.runtime.definition.rateLimit;
|
|
673
656
|
if (!policy || !who.request || who.actor || who.user && who.user.guest !== true) return;
|
|
@@ -694,7 +677,6 @@ function writeOptions(who) {
|
|
|
694
677
|
...who.waitUntil ? { waitUntil: who.waitUntil } : {}
|
|
695
678
|
};
|
|
696
679
|
}
|
|
697
|
-
/** A thread that does not exist and one that the caller may not read look the same: not found. */
|
|
698
680
|
async function load(who, threadIdValue) {
|
|
699
681
|
const found = await who.runtime.store.getById(threadIdValue);
|
|
700
682
|
if (!found || !await permitted(who, "read", { thread: found })) throw fail(commentsErrorDiagnostics.COMMENTS_R0002({ id: threadIdValue }), 404);
|
|
@@ -794,10 +776,6 @@ const commentInputSchemas = {
|
|
|
794
776
|
upload: uploadInput,
|
|
795
777
|
users: usersInput
|
|
796
778
|
};
|
|
797
|
-
/**
|
|
798
|
-
* The threads of a list that the caller may read, and how many threads the policy left out on the way. Threads the
|
|
799
|
-
* caller may not read are left out, so it asks again after them until the page is full or the threads end.
|
|
800
|
-
*/
|
|
801
779
|
async function readableThreads(input, who) {
|
|
802
780
|
const limit = input.limit ?? defaultLimit;
|
|
803
781
|
const readable = [];
|
|
@@ -825,7 +803,6 @@ async function readableThreads(input, who) {
|
|
|
825
803
|
};
|
|
826
804
|
}
|
|
827
805
|
const resolveNext = "After you make the change that a thread asks for, resolve it with comments.resolve and a reply that says what changed, such as the commit or a link. Resolve every thread that you handled in one call: { threads: [{ threadId, reply }] }. Open threads stay on the page.";
|
|
828
|
-
/** Threads that one search reads from the store at a time. */
|
|
829
806
|
const searchBatch = maximumLimit;
|
|
830
807
|
/**
|
|
831
808
|
* The comment actions behind every surface. The operations (RPC, CLI, MCP) and the overlay API call the same
|
|
@@ -880,7 +857,6 @@ const commentActions = {
|
|
|
880
857
|
if (!found || !await permitted(who, "read", { thread: found })) return null;
|
|
881
858
|
return (await withForge(who, [found]))[0];
|
|
882
859
|
},
|
|
883
|
-
/** `context` is the page context that the overlay read and its transport checked. */
|
|
884
860
|
async create(input, who) {
|
|
885
861
|
checkOutboxAccount(who);
|
|
886
862
|
const canRead = (thread) => permitted(who, "read", { thread });
|
|
@@ -901,7 +877,6 @@ const commentActions = {
|
|
|
901
877
|
canRead
|
|
902
878
|
});
|
|
903
879
|
},
|
|
904
|
-
/** `allowResolved`: the operations keep a reply box on resolved threads, and a reply keeps the thread resolved. */
|
|
905
880
|
async reply(input, who, options = {}) {
|
|
906
881
|
checkOutboxAccount(who);
|
|
907
882
|
const found = await load(who, input.threadId);
|
|
@@ -1018,7 +993,6 @@ const commentActions = {
|
|
|
1018
993
|
}
|
|
1019
994
|
return resolved;
|
|
1020
995
|
},
|
|
1021
|
-
/** `minimum`: the shortest query that gets suggestions. The operations ask for two characters. */
|
|
1022
996
|
async users(input, who, options = {}) {
|
|
1023
997
|
const thread = input.threadId === void 0 ? void 0 : await load(who, input.threadId);
|
|
1024
998
|
const target = thread ? { thread } : input.subject ? { subject: input.subject } : {};
|
|
@@ -1044,7 +1018,6 @@ const commentActions = {
|
|
|
1044
1018
|
await limitGuest(who);
|
|
1045
1019
|
return storeAttachment(who.runtime, input, who.user);
|
|
1046
1020
|
},
|
|
1047
|
-
/** The file of an attachment key, for a caller who may read a thread whose messages list it. */
|
|
1048
1021
|
async attachment(input, who) {
|
|
1049
1022
|
const thread = await attachmentThread(who.runtime, input.key, (candidate) => permitted(who, "read", { thread: candidate }));
|
|
1050
1023
|
return readAttachment(who.runtime, input.key, {
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as maximumCommentBodyLength } from "./service-
|
|
2
|
-
import { a as commentInputSchemas, i as commentAnchorSchema, n as CommentsCaller, o as commentsOperations, r as commentActions, t as CommentThreadsPage } from "./operations-
|
|
1
|
+
import { a as maximumCommentBodyLength } from "./service-qaMuJ7UX.js";
|
|
2
|
+
import { a as commentInputSchemas, i as commentAnchorSchema, n as CommentsCaller, o as commentsOperations, r as commentActions, t as CommentThreadsPage } from "./operations-D0EO1pzL.js";
|
|
3
3
|
export { CommentThreadsPage, CommentsCaller, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };
|
package/dist/operations.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-
|
|
2
|
-
import { f as maximumCommentBodyLength } from "./service-
|
|
1
|
+
import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-DHXmbtb3.js";
|
|
2
|
+
import { f as maximumCommentBodyLength } from "./service-DFMwCr60.js";
|
|
3
3
|
export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };
|