@vite-hub/comments 0.1.0 → 0.3.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 +79 -31
- package/dist/anchor.d.ts +7 -4
- package/dist/anchor.js +10 -5
- package/dist/client-diagnostics-CcFpkbAk.js +40 -0
- package/dist/client.d.ts +78 -3
- package/dist/client.js +198 -13
- package/dist/{console-BIz9t2cO.d.ts → console-h4KlhIik.d.ts} +97 -8
- package/dist/context-BqIsmYP1.js +61 -0
- package/dist/database/postgres.d.ts +738 -347
- package/dist/database/postgres.js +28 -7
- package/dist/{database-Cb2xjC1V.d.ts → database-CA1aHKN7.d.ts} +675 -276
- package/dist/database.d.ts +6 -98
- package/dist/database.js +2 -3
- package/dist/define-43mMR39K.js +89 -0
- package/dist/define-B3TF9zzn.d.ts +204 -0
- package/dist/errors-4gelGVmK.js +57 -0
- package/dist/errors-C6qptPoG.js +135 -0
- package/dist/errors-CyQyKAvy.d.ts +185 -0
- package/dist/fold-name-B7Zb3-MF.js +7 -0
- package/dist/{identity-3qtVC4rF.js → identity-CBOzgxSf.js} +7 -2
- package/dist/index-DNhy69Wt.d.ts +83 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +196 -5
- package/dist/install-BcMPgPk_.js +1154 -0
- package/dist/install-W9ghhGoh.d.ts +36 -0
- package/dist/installed-B-PfERBU.js +30 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/migrate-B0k_0swk.d.ts +54 -0
- package/dist/migrate-BDQ8xqUs.js +289 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/{operations-0B0QTVWX.d.ts → operations-D4A1Fcgf.d.ts} +37 -15
- package/dist/operations-DMMIfYPW.js +1159 -0
- package/dist/operations-GLeOqgMt.d.ts +257 -0
- package/dist/operations.d.ts +3 -7
- package/dist/operations.js +3 -2
- package/dist/overlay/client-DmsSMOzi.js +4 -0
- package/dist/overlay/dist-BoHMOFax.js +14 -0
- package/dist/overlay/dist-yIZmvSaU.js +1 -0
- package/dist/overlay/overlay.js +183 -177
- package/dist/page/loader.js +138 -18
- package/dist/{page-BuroSMXO.js → page-B41ozN63.js} +8 -6
- package/dist/{page-BtXADR6d.d.ts → page-DtbMOEMd.d.ts} +6 -5
- package/dist/page-tools-shared-NHUjKI8E.js +117 -0
- package/dist/path--zk6PEMz.js +18 -0
- package/dist/plugin-PS8PMYus.js +74 -0
- package/dist/realtime.d.ts +6 -12
- package/dist/realtime.js +23 -24
- package/dist/rpc-HBcWtg0T.d.ts +17 -0
- package/dist/rpc-RKPAusHp.js +153 -0
- package/dist/rpc.d.ts +2 -29
- package/dist/rpc.js +2 -75
- package/dist/runtime/auth.d.ts +5 -3
- package/dist/runtime/auth.js +8 -5
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +26 -21
- package/dist/runtime/index.d.ts +108 -60
- package/dist/runtime/index.js +684 -236
- package/dist/{server-BomGg3Gb.js → server-D8k-0GXe.js} +16 -7
- package/dist/server.d.ts +14 -88
- package/dist/server.js +7 -326
- package/dist/service-CFVm23k7.d.ts +158 -0
- package/dist/service-GHhhyQj4.js +609 -0
- package/dist/session-DVx-1Tym.d.ts +14 -0
- package/dist/session-EkudzUmm.js +503 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +14 -2
- package/dist/tokens-DSbwkVSy.js +58 -0
- package/dist/types-BIS0hCEl.d.ts +124 -0
- package/dist/types-CZujrMFd.d.ts +322 -0
- package/dist/vite.d.ts +91 -87
- package/dist/vite.js +535 -796
- package/package.json +24 -27
- package/dist/database-BSnVrwHn.js +0 -60
- package/dist/database-C-ktS9Do.js +0 -95
- package/dist/define-BzW2Ychn.d.ts +0 -46
- package/dist/define-Cbhl6QVJ.js +0 -32
- package/dist/errors-BAQYcy3_.d.ts +0 -89
- package/dist/errors-DeD6wTCl.js +0 -77
- package/dist/h3-v1-request-DDGXJ9E7.js +0 -166
- package/dist/index-DklG2Etf.d.ts +0 -111
- package/dist/operations-NZG5dB8y.js +0 -732
- package/dist/page-tools-shared-D-amu6sx.js +0 -53
- package/dist/plugin-QElKQYkA.js +0 -725
- package/dist/request-DVc3M_AG.js +0 -14
- package/dist/src-CRTwnaEG.js +0 -1362
- package/dist/types-Cj8K7Vx7.d.ts +0 -176
- package/dist/types-Un2dcJWD.d.ts +0 -288
package/dist/database.d.ts
CHANGED
|
@@ -1,104 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as commentsSchema, i as commentThreads, n as commentForge, r as commentMessages, t as commentCounters } from "./database-CA1aHKN7.js";
|
|
2
|
+
import { a as commentsMigrationSql, c as migrateComments, i as CommentsSchemaState, n as CommentsMigrationOptions, o as commentsSchemaState, s as liveThreadsBackup, t as CommentsMigration } from "./migrate-B0k_0swk.js";
|
|
3
3
|
//#region src/tables.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* The tables of `commentsSchema` as SQLite statements that are safe to run on every start. A database that Comments
|
|
6
|
-
* opens itself gets them on first use; a ViteHub Database gets the same tables from `vitehub
|
|
6
|
+
* opens itself gets them on first use; a ViteHub Database gets the same tables from `vitehub database generate` instead.
|
|
7
|
+
* A database that still has the tables of the live-site model needs `migrateComments()` first; `installComments()`
|
|
8
|
+
* runs it with `schema: "comments"`.
|
|
7
9
|
*/
|
|
8
10
|
export declare const commentsTables: readonly string[];
|
|
9
11
|
//#endregion
|
|
10
|
-
|
|
11
|
-
type Column<Table extends string, Data, NotNull extends boolean, PrimaryKey extends boolean = false, HasDefault extends boolean = false> = AnySQLiteColumn<{
|
|
12
|
-
data: Data;
|
|
13
|
-
hasDefault: HasDefault;
|
|
14
|
-
isPrimaryKey: PrimaryKey;
|
|
15
|
-
notNull: NotNull;
|
|
16
|
-
tableName: Table;
|
|
17
|
-
}> & {
|
|
18
|
-
_: {
|
|
19
|
-
generated: undefined;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
type ThreadColumn<Data, NotNull extends boolean, PrimaryKey extends boolean = false, HasDefault extends boolean = false> = Column<"vitehub_comment_threads", Data, NotNull, PrimaryKey, HasDefault>;
|
|
23
|
-
type CommentColumn<Data, NotNull extends boolean, PrimaryKey extends boolean = false> = Column<"vitehub_comments", Data, NotNull, PrimaryKey>;
|
|
24
|
-
type ForgeColumn<Data, NotNull extends boolean, PrimaryKey extends boolean = false, HasDefault extends boolean = false> = Column<"vitehub_comment_forge", Data, NotNull, PrimaryKey, HasDefault>;
|
|
25
|
-
/** The `vitehub_comment_forge` table, typed explicitly so its declaration can be emitted. */
|
|
26
|
-
export type CommentForgeTable = SQLiteTableWithColumns<{
|
|
27
|
-
columns: {
|
|
28
|
-
id: ForgeColumn<string, true, true>;
|
|
29
|
-
threadId: ForgeColumn<string, false>;
|
|
30
|
-
repository: ForgeColumn<string, true>;
|
|
31
|
-
pullRequest: ForgeColumn<number, true>;
|
|
32
|
-
remoteId: ForgeColumn<string, false>;
|
|
33
|
-
nodeId: ForgeColumn<string, false>;
|
|
34
|
-
url: ForgeColumn<string, false>;
|
|
35
|
-
digest: ForgeColumn<string, false>;
|
|
36
|
-
postedAs: ForgeColumn<"author" | "app", false>;
|
|
37
|
-
minimized: ForgeColumn<boolean, true, false, true>;
|
|
38
|
-
error: ForgeColumn<string, false>;
|
|
39
|
-
updatedAt: ForgeColumn<number, true>;
|
|
40
|
-
};
|
|
41
|
-
dialect: "sqlite";
|
|
42
|
-
name: "vitehub_comment_forge";
|
|
43
|
-
schema: undefined;
|
|
44
|
-
}>;
|
|
45
|
-
/** The `vitehub_comment_threads` table, typed explicitly so its declaration can be emitted. */
|
|
46
|
-
export type CommentThreadsTable = SQLiteTableWithColumns<{
|
|
47
|
-
columns: {
|
|
48
|
-
id: ThreadColumn<string, true, true>;
|
|
49
|
-
scope: ThreadColumn<string, true, false, true>;
|
|
50
|
-
number: ThreadColumn<number, true, false, true>;
|
|
51
|
-
page: ThreadColumn<string, true>;
|
|
52
|
-
anchor: ThreadColumn<string, true>;
|
|
53
|
-
context: ThreadColumn<string, false>;
|
|
54
|
-
metadata: ThreadColumn<string, false>;
|
|
55
|
-
status: ThreadColumn<"open" | "resolved", true>;
|
|
56
|
-
createdBy: ThreadColumn<string, true>;
|
|
57
|
-
resolvedBy: ThreadColumn<string, false>;
|
|
58
|
-
resolvedAt: ThreadColumn<number, false>;
|
|
59
|
-
createdAt: ThreadColumn<number, true>;
|
|
60
|
-
updatedAt: ThreadColumn<number, true>;
|
|
61
|
-
};
|
|
62
|
-
dialect: "sqlite";
|
|
63
|
-
name: "vitehub_comment_threads";
|
|
64
|
-
schema: undefined;
|
|
65
|
-
}>;
|
|
66
|
-
/** Allocation history survives thread and scope deletion. */
|
|
67
|
-
export type CommentScopeCountersTable = SQLiteTableWithColumns<{
|
|
68
|
-
columns: {
|
|
69
|
-
scope: Column<"vitehub_comment_scope_counters", string, true, true>;
|
|
70
|
-
lastNumber: Column<"vitehub_comment_scope_counters", number, true>;
|
|
71
|
-
};
|
|
72
|
-
dialect: "sqlite";
|
|
73
|
-
name: "vitehub_comment_scope_counters";
|
|
74
|
-
schema: undefined;
|
|
75
|
-
}>;
|
|
76
|
-
/** The `vitehub_comments` table, typed explicitly so its declaration can be emitted. */
|
|
77
|
-
export type CommentsTable = SQLiteTableWithColumns<{
|
|
78
|
-
columns: {
|
|
79
|
-
id: CommentColumn<string, true, true>;
|
|
80
|
-
threadId: CommentColumn<string, true>;
|
|
81
|
-
body: CommentColumn<string, true>;
|
|
82
|
-
mentions: CommentColumn<string, true>;
|
|
83
|
-
author: CommentColumn<string, true>;
|
|
84
|
-
createdAt: CommentColumn<number, true>;
|
|
85
|
-
editedAt: CommentColumn<number, false>;
|
|
86
|
-
};
|
|
87
|
-
dialect: "sqlite";
|
|
88
|
-
name: "vitehub_comments";
|
|
89
|
-
schema: undefined;
|
|
90
|
-
}>;
|
|
91
|
-
/**
|
|
92
|
-
* The tables behind Comments, including forge links and scope numbering. ViteHub adds them to the Database of
|
|
93
|
-
* `defineComments({ database })` for you; add them yourself only to a Database configured without ViteHub.
|
|
94
|
-
* For existing tables, follow https://vitehub.dev/docs/comments/configure#upgrade-existing-comments before
|
|
95
|
-
* applying the migration that `vitehub db generate` writes.
|
|
96
|
-
*/
|
|
97
|
-
declare const commentsSchema$1: {
|
|
98
|
-
vitehubCommentThreads: CommentThreadsTable;
|
|
99
|
-
vitehubComments: CommentsTable;
|
|
100
|
-
vitehubCommentForge: CommentForgeTable;
|
|
101
|
-
vitehubCommentScopeCounters: CommentScopeCountersTable;
|
|
102
|
-
};
|
|
103
|
-
//#endregion
|
|
104
|
-
export { commentCounters, commentMessages, commentThreads, commentsSchema as commentsOperationsSchema, commentsSchema$1 as commentsSchema };
|
|
12
|
+
export { type CommentsMigration, type CommentsMigrationOptions, type CommentsSchemaState, commentCounters, commentForge, commentMessages, commentThreads, commentsMigrationSql, commentsSchema, commentsSchemaState, liveThreadsBackup, migrateComments };
|
package/dist/database.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export { commentCounters, commentMessages, commentThreads, commentsSchema as commentsOperationsSchema, commentsSchema$1 as commentsSchema, commentsTables };
|
|
1
|
+
import { a as migrateComments, c as commentForge, d as commentsSchema, i as liveThreadsBackup, l as commentMessages, o as commentsTables, r as commentsSchemaState, s as commentCounters, t as commentsMigrationSql, u as commentThreads } from "./migrate-BDQ8xqUs.js";
|
|
2
|
+
export { commentCounters, commentForge, commentMessages, commentThreads, commentsMigrationSql, commentsSchema, commentsSchemaState, commentsTables, liveThreadsBackup, migrateComments };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
|
|
2
|
+
//#region src/operations-core/define.ts
|
|
3
|
+
const marker = Symbol.for("vitehub.comments.definition");
|
|
4
|
+
/** Marks a definition, so the build can check what `server/comments.ts` exports. */
|
|
5
|
+
function markCommentsDefinition(definition) {
|
|
6
|
+
Object.defineProperty(definition, marker, { value: true });
|
|
7
|
+
return definition;
|
|
8
|
+
}
|
|
9
|
+
function isCommentsDefinition(value) {
|
|
10
|
+
return value !== null && Object(value) === value && Reflect.get(Object(value), marker) === true;
|
|
11
|
+
}
|
|
12
|
+
/** Validate the imported application module before installing its runtime. */
|
|
13
|
+
function validateCommentsDefinition(value, file) {
|
|
14
|
+
if (!isCommentsDefinition(value)) throw commentsErrorDiagnostics.COMMENTS_B0002({ file });
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
/** A subject kind of your own, such as `drop`. */
|
|
18
|
+
function defineCommentSubject(subject) {
|
|
19
|
+
return Object.freeze({ ...subject });
|
|
20
|
+
}
|
|
21
|
+
/** Subjects that exist without a definition. */
|
|
22
|
+
const builtinCommentSubjects = [defineCommentSubject({
|
|
23
|
+
kind: "page",
|
|
24
|
+
scope: () => "site",
|
|
25
|
+
link: (thread) => `${thread.subject.id}?comment=${thread.n}`
|
|
26
|
+
}), defineCommentSubject({
|
|
27
|
+
kind: "content",
|
|
28
|
+
scope: () => "site"
|
|
29
|
+
})];
|
|
30
|
+
/** The roles of a user: the comma-separated `role` of Better Auth's `admin()` plugin, as ViteHub Auth passes it on. */
|
|
31
|
+
function rolesOf(user) {
|
|
32
|
+
const role = user?.role;
|
|
33
|
+
return typeof role === "string" ? role.split(",").map((name) => name.trim()) : [];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether the roles of a user allow an action: the role `comments-<action>`, or for `read`, any `comments-` role.
|
|
37
|
+
* Site access in the Console gives these roles to the people it signs in. In `authorize`, check them first:
|
|
38
|
+
* `authorize: ({ user, action }) => commentsRoleAllows(user, action) || user?.role === "admin"`.
|
|
39
|
+
*/
|
|
40
|
+
function commentsRoleAllows(user, action) {
|
|
41
|
+
const roles = rolesOf(user);
|
|
42
|
+
return roles.includes(`comments-${action}`) || action === "read" && roles.some((role) => role.startsWith("comments-"));
|
|
43
|
+
}
|
|
44
|
+
/** The roles that Comments offers to Site access in the Console, for the guests that someone invites. */
|
|
45
|
+
const commentsRoleGrants = [
|
|
46
|
+
{
|
|
47
|
+
id: "comments-read",
|
|
48
|
+
label: "Read comments",
|
|
49
|
+
description: "See the comments on every page."
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "comments-write",
|
|
53
|
+
label: "Write comments",
|
|
54
|
+
description: "Start threads and reply."
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "comments-resolve",
|
|
58
|
+
label: "Resolve threads",
|
|
59
|
+
description: "Resolve and reopen threads."
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: "comments-delete",
|
|
63
|
+
label: "Delete comments",
|
|
64
|
+
description: "Delete threads and messages."
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
/**
|
|
68
|
+
* The policy without `authorize`, for every action. On the development server, everyone may, anonymous people as
|
|
69
|
+
* guests. In a production build, only people that a sign-in already vetted: a person signed in with GitHub who can
|
|
70
|
+
* push to the repository of the build, or a person that the Console admitted to its Comments section through the
|
|
71
|
+
* comment operations or the Console MCP tools, and a user whose roles allow the action, which Site access in the Console
|
|
72
|
+
* gives (see `commentsRoleAllows()`). Other users of ViteHub Auth or `identify` get nothing until `authorize` says
|
|
73
|
+
* who may, because any visitor may be able to sign up. On the page, only people signed in with GitHub get in.
|
|
74
|
+
*/
|
|
75
|
+
function defaultPolicy(user, gate = {}, action) {
|
|
76
|
+
if (action && commentsRoleAllows(user, action)) return true;
|
|
77
|
+
if (user?.github) return user.github.write;
|
|
78
|
+
if (gate.development === true) return true;
|
|
79
|
+
return user !== null && gate.console === true;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether the default policy denied `user` only because `server/comments.ts` has no `authorize`: a signed-in person
|
|
83
|
+
* in a production build that neither GitHub nor the Console vetted. The diagnostics then name the missing policy.
|
|
84
|
+
*/
|
|
85
|
+
function deniedForMissingPolicy(definition, user, gate = {}) {
|
|
86
|
+
return !definition.authorize && user !== null && user.guest !== true && !user.github && gate.development !== true && gate.console !== true && !rolesOf(user).some((role) => role.startsWith("comments-"));
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { defineCommentSubject as a, validateCommentsDefinition as c, defaultPolicy as i, commentsRoleAllows as n, deniedForMissingPolicy as o, commentsRoleGrants as r, markCommentsDefinition as s, builtinCommentSubjects as t };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { S as CommentThread, _ as CommentMetadata, g as CommentMessage, n as CommentActor, w as CommentUser, x as CommentSubject } from "./types-CZujrMFd.js";
|
|
2
|
+
//#region src/operations-core/define.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* - `read`: see threads, join the presence room of a page, and get `@` suggestions.
|
|
5
|
+
* - `write`: start threads and reply. Signed-in authors also edit and delete their own messages.
|
|
6
|
+
* - `resolve`: resolve and reopen.
|
|
7
|
+
* - `delete`: delete the messages and threads of other people.
|
|
8
|
+
*/
|
|
9
|
+
type CommentAction = "read" | "write" | "resolve" | "delete";
|
|
10
|
+
/** What GitHub says about a person who signed in to Comments with GitHub. */
|
|
11
|
+
interface CommentsGitHubAccess {
|
|
12
|
+
/** Their GitHub username. */
|
|
13
|
+
login: string;
|
|
14
|
+
/** The repository of the build, `owner/name`, when Comments knows it. */
|
|
15
|
+
repository?: string;
|
|
16
|
+
/** Whether they can push to `repository`. False when Comments does not know the repository. */
|
|
17
|
+
write: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The user of a request, with the application fields that a policy reads, such as `role`. `null` for an anonymous
|
|
21
|
+
* request. Stored authors keep only `id`, `name`, and `image`.
|
|
22
|
+
*/
|
|
23
|
+
type CommentsUser = Record<string, unknown> & {
|
|
24
|
+
id: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
image?: string;
|
|
27
|
+
/** A guest that named itself in the browser. */
|
|
28
|
+
guest?: boolean;
|
|
29
|
+
/** For a person who signed in to Comments with GitHub. */
|
|
30
|
+
github?: CommentsGitHubAccess;
|
|
31
|
+
};
|
|
32
|
+
interface CommentsAuthorizeContext {
|
|
33
|
+
/** The signed-in user, including application fields such as `role`, or null. */
|
|
34
|
+
user: CommentsUser | null;
|
|
35
|
+
/** The Agent Actor when an agent acts for `user`. */
|
|
36
|
+
actor?: CommentActor;
|
|
37
|
+
action: CommentAction;
|
|
38
|
+
/** The thread that the action is about. Not set for `create`, `list`, and `users`. */
|
|
39
|
+
thread?: CommentThread;
|
|
40
|
+
/**
|
|
41
|
+
* What the action is about: the subject of `thread`, the subject that `create` starts a thread on, or the subject
|
|
42
|
+
* that a `list` filters by. Not set for a `list` with no filter and for `users`.
|
|
43
|
+
*/
|
|
44
|
+
subject?: CommentSubject;
|
|
45
|
+
/**
|
|
46
|
+
* The Console admitted the caller to its Comments section before Comments ran: the comment operations of the
|
|
47
|
+
* Console, the CLI, and ViteHub MCP, and `commentsMcpTools(comments, { console: true })`. Not set for the overlay.
|
|
48
|
+
* With `identify`, such a call often has no app user, so allow it here:
|
|
49
|
+
* `authorize: ({ console, user }) => console === true || user?.role === "editor"`.
|
|
50
|
+
*/
|
|
51
|
+
console?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/** Decides whether a person or an Agent may take an action. Return `true` to allow. */
|
|
54
|
+
type CommentsAuthorize = (context: CommentsAuthorizeContext) => boolean | Promise<boolean>;
|
|
55
|
+
/** A kind of subject that threads can be about. */
|
|
56
|
+
interface CommentSubjectDefinition {
|
|
57
|
+
kind: string;
|
|
58
|
+
/** The numbering scope of a subject id. `n` is unique inside a scope. */
|
|
59
|
+
scope: (subjectId: string) => string;
|
|
60
|
+
/**
|
|
61
|
+
* Whether a message on this subject may have no text, such as a suggestion that keeps its text in `metadata`. A
|
|
62
|
+
* function gets the `metadata` of the thread. A message with attachments may always have no text. Default `false`.
|
|
63
|
+
*/
|
|
64
|
+
emptyBody?: boolean | ((thread: {
|
|
65
|
+
metadata?: CommentMetadata;
|
|
66
|
+
}) => boolean);
|
|
67
|
+
/** The app path that opens a thread, such as `/docs/42?comment=3`. `onMention` passes it as `link`. */
|
|
68
|
+
link?: (thread: CommentThread) => string | undefined;
|
|
69
|
+
}
|
|
70
|
+
/** Where `@` finds people. */
|
|
71
|
+
interface CommentsPeople {
|
|
72
|
+
/**
|
|
73
|
+
* People whose name contains `query`, with the fields that `canMention` reads. Comments returns only their `id`,
|
|
74
|
+
* `name`, and `image`.
|
|
75
|
+
*/
|
|
76
|
+
search: (query: string, limit: number) => Promise<CommentUser[]> | CommentUser[];
|
|
77
|
+
/** The people with these ids, including fields that `authorize` reads. An id that is not a person is left out. */
|
|
78
|
+
byIds: (ids: readonly string[]) => Promise<CommentUser[]> | CommentUser[];
|
|
79
|
+
}
|
|
80
|
+
interface CommentsCanMentionContext {
|
|
81
|
+
/** The person who writes the message. */
|
|
82
|
+
user: CommentsUser | null;
|
|
83
|
+
/** The person that the message would mention. */
|
|
84
|
+
person: CommentUser & Record<string, unknown>;
|
|
85
|
+
/** The thread of the message. Not set for a new thread. */
|
|
86
|
+
thread?: CommentThread;
|
|
87
|
+
/** The subject of the thread, or of the new thread. */
|
|
88
|
+
subject?: CommentSubject;
|
|
89
|
+
}
|
|
90
|
+
interface CommentMentionEvent {
|
|
91
|
+
thread: CommentThread;
|
|
92
|
+
message: CommentMessage;
|
|
93
|
+
/** The people that this message mentions for the first time. */
|
|
94
|
+
users: CommentUser[];
|
|
95
|
+
/** The app path that opens the thread, when its subject has one, such as `/pricing?comment=3`. */
|
|
96
|
+
link?: string;
|
|
97
|
+
}
|
|
98
|
+
interface CommentMessageEvent {
|
|
99
|
+
thread: CommentThread;
|
|
100
|
+
message: CommentMessage;
|
|
101
|
+
/** The people that the message mentions. */
|
|
102
|
+
mentions: CommentUser[];
|
|
103
|
+
}
|
|
104
|
+
/** A file to attach, after Comments checked its size and type. */
|
|
105
|
+
interface CommentsAttachmentFile {
|
|
106
|
+
name: string;
|
|
107
|
+
type: string;
|
|
108
|
+
size: number;
|
|
109
|
+
data: Uint8Array;
|
|
110
|
+
}
|
|
111
|
+
interface CommentsStoreAttachmentContext {
|
|
112
|
+
user: CommentsUser | null;
|
|
113
|
+
subject?: CommentSubject;
|
|
114
|
+
}
|
|
115
|
+
interface CommentsReadAttachmentContext {
|
|
116
|
+
/** The person who reads the file. Comments checked that they may read `thread`. */
|
|
117
|
+
user: CommentsUser | null;
|
|
118
|
+
/** A thread with a message that lists the key, which the reader may read. */
|
|
119
|
+
thread: CommentThread;
|
|
120
|
+
}
|
|
121
|
+
/** A fixed-window budget for each guest address, the same shape as `defineForm({ rateLimit })`. */
|
|
122
|
+
interface CommentsRateLimit {
|
|
123
|
+
limit: number;
|
|
124
|
+
/** A duration such as `30s`, `1m`, or `1h`. */
|
|
125
|
+
window: string;
|
|
126
|
+
}
|
|
127
|
+
interface CommentsDefinition {
|
|
128
|
+
/**
|
|
129
|
+
* Who may read, write, resolve, and delete. Return `true` to allow. Without it, see `defaultPolicy()`: everyone on
|
|
130
|
+
* the development server; in a production build, people signed in with GitHub who can push to the repository, and
|
|
131
|
+
* people that the Console admits to its Comments section. Nobody else until you set it.
|
|
132
|
+
*/
|
|
133
|
+
authorize?: CommentsAuthorize;
|
|
134
|
+
/** Subject kinds in addition to `page` (scope `site`) and `content` (scope `site`). */
|
|
135
|
+
subjects?: readonly CommentSubjectDefinition[];
|
|
136
|
+
/**
|
|
137
|
+
* Where `@` finds people. Without it: the users of ViteHub Auth when the app has Auth, else the people who wrote
|
|
138
|
+
* earlier comments in threads that the writer may read.
|
|
139
|
+
*/
|
|
140
|
+
people?: CommentsPeople;
|
|
141
|
+
/**
|
|
142
|
+
* Whether `user` may mention `person` in a thread. Suggestions leave out the people it refuses, and a message that
|
|
143
|
+
* mentions one fails. Default: `person` may read the thread.
|
|
144
|
+
*/
|
|
145
|
+
canMention?: (context: CommentsCanMentionContext) => boolean | Promise<boolean>;
|
|
146
|
+
/**
|
|
147
|
+
* Runs once for each saved message that mentions people for the first time, with those people. It runs after the
|
|
148
|
+
* answer, through `waitUntil` where the host has it. A failure is logged and never fails the comment.
|
|
149
|
+
*/
|
|
150
|
+
onMention?: (event: CommentMentionEvent) => void | Promise<void>;
|
|
151
|
+
/** Runs after each new thread and each reply saves, before the answer. Errors are logged, not returned. */
|
|
152
|
+
onComment?: (event: CommentMessageEvent) => void | Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Stores an uploaded file and returns its key, which messages keep in `attachments`. Without it, Comments stores the
|
|
155
|
+
* file in the Blob store of the app under `comments/`.
|
|
156
|
+
*/
|
|
157
|
+
storeAttachment?: (file: CommentsAttachmentFile, context: CommentsStoreAttachmentContext) => string | Promise<string>;
|
|
158
|
+
/**
|
|
159
|
+
* Reads a file that `storeAttachment` stored, for `GET /attachments/<key>` and `comments.attachment`. Return a
|
|
160
|
+
* `Blob` (or a `File`) with its media type, or `null` when the file is gone. Comments checks first that the reader
|
|
161
|
+
* may read a thread whose messages list the key. Without it, Comments reads only its upload keys under
|
|
162
|
+
* `comments/<uuid>/<name>` in the Blob store of the app. Use this hook to authorize reads of other app files.
|
|
163
|
+
*/
|
|
164
|
+
readAttachment?: (key: string, context: CommentsReadAttachmentContext) => Blob | null | Promise<Blob | null>;
|
|
165
|
+
/**
|
|
166
|
+
* How many writes each guest address may make in a window, such as `{ limit: 5, window: "1m" }`. Each new thread,
|
|
167
|
+
* reply, and upload of a guest counts. A refused write fails with `COMMENTS_GUEST_RATE_LIMITED` and status 429.
|
|
168
|
+
* Signed-in people and Agents are not limited. Default: guests are not limited.
|
|
169
|
+
*/
|
|
170
|
+
rateLimit?: CommentsRateLimit;
|
|
171
|
+
}
|
|
172
|
+
/** Validate the imported application module before installing its runtime. */
|
|
173
|
+
declare function validateCommentsDefinition(value: unknown, file: string): CommentsDefinition;
|
|
174
|
+
/** A subject kind of your own, such as `drop`. */
|
|
175
|
+
declare function defineCommentSubject(subject: CommentSubjectDefinition): CommentSubjectDefinition;
|
|
176
|
+
/** Subjects that exist without a definition. */
|
|
177
|
+
declare const builtinCommentSubjects: readonly CommentSubjectDefinition[];
|
|
178
|
+
/** What the server checked about a request before the policy runs. */
|
|
179
|
+
interface CommentsPolicyGate {
|
|
180
|
+
/** Vite's serve command. The generated Nitro plugin records it; it never comes from `NODE_ENV`. */
|
|
181
|
+
development?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* The Console admitted the person to its Comments section before Comments ran: the comment operations of the
|
|
184
|
+
* Operations endpoint, the CLI, and the Console MCP tools. The overlay API never sets it.
|
|
185
|
+
*/
|
|
186
|
+
console?: boolean;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Whether the roles of a user allow an action: the role `comments-<action>`, or for `read`, any `comments-` role.
|
|
190
|
+
* Site access in the Console gives these roles to the people it signs in. In `authorize`, check them first:
|
|
191
|
+
* `authorize: ({ user, action }) => commentsRoleAllows(user, action) || user?.role === "admin"`.
|
|
192
|
+
*/
|
|
193
|
+
declare function commentsRoleAllows(user: CommentsUser | null, action: CommentAction): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* The policy without `authorize`, for every action. On the development server, everyone may, anonymous people as
|
|
196
|
+
* guests. In a production build, only people that a sign-in already vetted: a person signed in with GitHub who can
|
|
197
|
+
* push to the repository of the build, or a person that the Console admitted to its Comments section through the
|
|
198
|
+
* comment operations or the Console MCP tools, and a user whose roles allow the action, which Site access in the Console
|
|
199
|
+
* gives (see `commentsRoleAllows()`). Other users of ViteHub Auth or `identify` get nothing until `authorize` says
|
|
200
|
+
* who may, because any visitor may be able to sign up. On the page, only people signed in with GitHub get in.
|
|
201
|
+
*/
|
|
202
|
+
declare function defaultPolicy(user: CommentsUser | null, gate?: CommentsPolicyGate, action?: CommentAction): boolean;
|
|
203
|
+
//#endregion
|
|
204
|
+
export { builtinCommentSubjects as _, CommentsAttachmentFile as a, defineCommentSubject as b, CommentsCanMentionContext as c, CommentsPeople as d, CommentsPolicyGate as f, CommentsUser as g, CommentsStoreAttachmentContext as h, CommentSubjectDefinition as i, CommentsDefinition as l, CommentsReadAttachmentContext as m, CommentMentionEvent as n, CommentsAuthorize as o, CommentsRateLimit as p, CommentMessageEvent as r, CommentsAuthorizeContext as s, CommentAction as t, CommentsGitHubAccess as u, commentsRoleAllows as v, validateCommentsDefinition as x, defaultPolicy as y };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { defineErrors } from "@vite-hub/runtime";
|
|
2
|
+
//#region src/errors.ts
|
|
3
|
+
const commentsErrors = /*#__PURE__*/ defineErrors({
|
|
4
|
+
docs: "https://vitehub.dev/docs/comments/diagnostics",
|
|
5
|
+
codes: {
|
|
6
|
+
COMMENTS_NOT_INSTALLED: {
|
|
7
|
+
why: "The Comments runtime has no Database yet. ViteHub installs it from `server/comments.ts` when the server starts.",
|
|
8
|
+
fix: "Call the method from a server route or a Nitro plugin of the app, not at import time, and enable a Database with `vitehub({ database: true })`."
|
|
9
|
+
},
|
|
10
|
+
COMMENTS_NOT_FOUND: {
|
|
11
|
+
why: ({ id }) => `No comment thread or comment has the id ${JSON.stringify(id)}.`,
|
|
12
|
+
fix: "List the threads with `comments.list()` and use one of their ids. A deleted thread does not come back."
|
|
13
|
+
},
|
|
14
|
+
COMMENTS_INVALID_INPUT: {
|
|
15
|
+
why: ({ issue }) => `The comment input is not valid: ${issue}`,
|
|
16
|
+
fix: "Send a page path that starts with `/`, an anchor from the overlay, and a body of 1 to 4,000 characters."
|
|
17
|
+
},
|
|
18
|
+
COMMENTS_FORBIDDEN: {
|
|
19
|
+
why: ({ action }) => `The \`authorize\` policy of \`defineComments()\` denied \`${action}\` for this user.`,
|
|
20
|
+
fix: "Sign in as a user that the policy allows, or change `authorize` in `server/comments.ts`."
|
|
21
|
+
},
|
|
22
|
+
COMMENTS_POLICY_MISSING: {
|
|
23
|
+
why: "`server/comments.ts` has no `authorize` policy, so a production build lets in only people signed in with GitHub who can push to the repository, and people that the Console admits to its Comments section.",
|
|
24
|
+
fix: "Pass `authorize` to `defineComments()` and return `true` for the people that may read, write, resolve, or delete."
|
|
25
|
+
},
|
|
26
|
+
COMMENTS_RESOLVED: {
|
|
27
|
+
why: "The thread is resolved, so it takes no new replies.",
|
|
28
|
+
fix: "Reopen the thread with `comments.reopen(id)` first."
|
|
29
|
+
},
|
|
30
|
+
COMMENTS_CONTENT_MISSING: {
|
|
31
|
+
why: "Inline edits need Content, and the app has no `server/content.ts` with document collections.",
|
|
32
|
+
fix: "Define collections with `defineContent()` in `server/content.ts`, and mark rendered fields with `contentField()`."
|
|
33
|
+
},
|
|
34
|
+
COMMENTS_FIELD_INVALID: {
|
|
35
|
+
why: ({ field }) => `${JSON.stringify(field)} is not a Content field address, or its collection, document, or field does not exist.`,
|
|
36
|
+
fix: "Write the attribute with `contentField(collection, id, field)` from `vite-hub/content/client`, so the address matches a collection of `server/content.ts`."
|
|
37
|
+
},
|
|
38
|
+
COMMENTS_FIELD_NOT_EDITABLE: {
|
|
39
|
+
why: ({ field }) => `The draft value of ${JSON.stringify(field)} is not a string, so it cannot be edited as text on the page.`,
|
|
40
|
+
fix: "Edit the field in the Console Content editor."
|
|
41
|
+
},
|
|
42
|
+
COMMENTS_FIELD_FORBIDDEN: {
|
|
43
|
+
why: ({ field }) => `\`content.can()\` denied \`write\` on the document of ${JSON.stringify(field)} for this user.`,
|
|
44
|
+
fix: "Sign in as a user that the `authorize` policy of `defineContent()` lets write the collection."
|
|
45
|
+
},
|
|
46
|
+
COMMENTS_FIELD_CONFLICT: {
|
|
47
|
+
why: ({ field }) => `The document of ${JSON.stringify(field)} changed after the page read it.`,
|
|
48
|
+
fix: "Open the field again to read the current draft, then repeat the edit."
|
|
49
|
+
},
|
|
50
|
+
COMMENTS_FIELD_LOCKED: {
|
|
51
|
+
why: ({ holder }) => `${holder} holds the edit lease of this document in the Console.`,
|
|
52
|
+
fix: "Wait until they close the document, or edit it together with them in the Console."
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
//#endregion
|
|
57
|
+
export { commentsErrors as t };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { n as commentsClientCodes } from "./client-diagnostics-CcFpkbAk.js";
|
|
2
|
+
import { defineDiagnostics } from "nostics";
|
|
3
|
+
//#region src/operations-core/errors.ts
|
|
4
|
+
const commentsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
5
|
+
docsBase: "https://vitehub.dev/docs/comments/diagnostics",
|
|
6
|
+
codes: {
|
|
7
|
+
...commentsClientCodes,
|
|
8
|
+
COMMENTS_R0002: {
|
|
9
|
+
why: ({ id }) => `The comment thread "${id}" does not exist.`,
|
|
10
|
+
fix: "List the threads again, because someone may have deleted this one."
|
|
11
|
+
},
|
|
12
|
+
COMMENTS_R0003: {
|
|
13
|
+
why: ({ messageId }) => `The comment message "${messageId}" does not exist in this thread.`,
|
|
14
|
+
fix: "Read the thread again, because someone may have deleted the message."
|
|
15
|
+
},
|
|
16
|
+
COMMENTS_R0004: {
|
|
17
|
+
why: "Only the author of a message can edit or delete it.",
|
|
18
|
+
fix: "Sign in as the author, or ask them to change the message."
|
|
19
|
+
},
|
|
20
|
+
COMMENTS_R0005: {
|
|
21
|
+
why: "A comment needs some text.",
|
|
22
|
+
fix: "Write at least one character before you send."
|
|
23
|
+
},
|
|
24
|
+
COMMENTS_R0006: {
|
|
25
|
+
why: "server/comments.ts defines no authorize policy, so a production build lets in only people signed in with GitHub who can push to the repository, and people that the Console admits to its Comments section. Other signed-in people, such as users of ViteHub Auth or identify, get nothing.",
|
|
26
|
+
fix: "Pass authorize to defineComments({ authorize }) and return true for the people and Agents that may take the action. See https://vitehub.dev/docs/comments/configure#decide-who-can-comment"
|
|
27
|
+
},
|
|
28
|
+
COMMENTS_R0007: {
|
|
29
|
+
why: ({ message }) => message,
|
|
30
|
+
fix: "Mention only people that users() finds, and write @ and their name in the text."
|
|
31
|
+
},
|
|
32
|
+
COMMENTS_R0008: {
|
|
33
|
+
why: ({ kind }) => `The comment subject kind "${kind}" is not defined.`,
|
|
34
|
+
fix: "Use page or content, or add defineCommentSubject({ kind, scope }) to defineComments({ subjects })."
|
|
35
|
+
},
|
|
36
|
+
COMMENTS_R0009: {
|
|
37
|
+
why: ({ action }) => `This user or Agent may not ${action} this comment.`,
|
|
38
|
+
fix: "Ask for access, or allow the action in defineComments({ authorize })."
|
|
39
|
+
},
|
|
40
|
+
COMMENTS_R0010: {
|
|
41
|
+
why: "The comments runtime is not installed.",
|
|
42
|
+
fix: "Add server/comments.ts and enable the Database with vitehub({ database: true }). `vite dev` and builds install the runtime for you."
|
|
43
|
+
},
|
|
44
|
+
COMMENTS_R0011: {
|
|
45
|
+
why: "The comment numbers of this scope are busy.",
|
|
46
|
+
fix: "Try again. Several people created a comment at the same moment."
|
|
47
|
+
},
|
|
48
|
+
COMMENTS_R0012: {
|
|
49
|
+
why: "Writing a comment needs a signed-in user.",
|
|
50
|
+
fix: "Sign in, then try again. Without ViteHub Auth or `identify`, sign in with GitHub so comments know who writes."
|
|
51
|
+
},
|
|
52
|
+
COMMENTS_R0014: {
|
|
53
|
+
why: "Comments has no place to store attachments: the app has no Blob store and no storeAttachment hook.",
|
|
54
|
+
fix: "Turn on Blob with vitehub({ blob: true }), or pass storeAttachment to defineComments()."
|
|
55
|
+
},
|
|
56
|
+
COMMENTS_R0016: {
|
|
57
|
+
why: "The thread is resolved, so it takes no new replies.",
|
|
58
|
+
fix: "Reopen the thread first, or pass { allowResolved: true } to comments.reply() when your UI allows replies to resolved threads."
|
|
59
|
+
},
|
|
60
|
+
COMMENTS_R0017: {
|
|
61
|
+
why: ({ message }) => message,
|
|
62
|
+
fix: "Attach an image, a PDF, or a text file of at most 5 MB."
|
|
63
|
+
},
|
|
64
|
+
COMMENTS_R0018: {
|
|
65
|
+
why: ({ message }) => message,
|
|
66
|
+
fix: "Check the input against the limits of comments: https://vitehub.dev/docs/comments/limits-and-errors"
|
|
67
|
+
},
|
|
68
|
+
COMMENTS_R0019: {
|
|
69
|
+
why: ({ state, missing }) => state === "live" ? "The Database still has the comment tables of the live-site model (vitehub_comment_threads with number, page, and created_by), so Comments cannot read or write threads." : state === "outdated" ? `The vitehub_comment_threads table misses columns of this version: ${missing.join(", ")}.` : "The Database has no comment tables.",
|
|
70
|
+
fix: ({ state }) => state === "live" ? "Move the tables once in a custom migration: run vitehub database generate --custom --schema-snapshot --name comments_one_model, put the SQL of commentsMigrationSql({ from: \"live\" }) from vite-hub/comments/database in it, then run vitehub database migrate. See https://vitehub.dev/docs/comments/configure#upgrade-to-one-model" : "Run vitehub database generate and vitehub database migrate, so the Database gets the comment tables of this version. See https://vitehub.dev/docs/comments/configure#upgrade-to-one-model"
|
|
71
|
+
},
|
|
72
|
+
COMMENTS_R0020: {
|
|
73
|
+
why: ({ key }) => `No comment that you may read has the attachment ${JSON.stringify(key)}, or its file is gone.`,
|
|
74
|
+
fix: "Read the attachment through a message that lists its key, as a person who may read that thread."
|
|
75
|
+
},
|
|
76
|
+
COMMENTS_R0021: {
|
|
77
|
+
why: "Comments stores attachments with storeAttachment, but has no readAttachment to read them back.",
|
|
78
|
+
fix: "Pass readAttachment to defineComments(), next to storeAttachment, and return the file of the key as a Blob."
|
|
79
|
+
},
|
|
80
|
+
COMMENTS_R0022: {
|
|
81
|
+
why: "Another comment thread of this scope already uses this requestId: it has another author or another subject, or you may not read it.",
|
|
82
|
+
fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment. Send the same requestId again only to retry the same comment."
|
|
83
|
+
},
|
|
84
|
+
COMMENTS_B0001: {
|
|
85
|
+
why: ({ file }) => `${file} needs a Database, but the Database is off for this app.`,
|
|
86
|
+
fix: "Remove `database: false` from vitehub(), or set `database: true`. vitehub() turns the Database on for comments when the option is unset."
|
|
87
|
+
},
|
|
88
|
+
COMMENTS_B0002: {
|
|
89
|
+
why: ({ file }) => `${file} must export defineComments(), as \`comments\` or as the default export.`,
|
|
90
|
+
fix: "Write `export default defineComments({ authorize })` in server/comments.ts."
|
|
91
|
+
},
|
|
92
|
+
COMMENTS_B0003: {
|
|
93
|
+
why: "comments() from @vite-hub/comments/vite is for apps without vitehub(). In this app vitehub() owns the Comments configuration.",
|
|
94
|
+
fix: "Remove comments() from the plugins and set vitehub({ comments: true }), or add server/comments.ts. See https://vitehub.dev/docs/comments/configure#turn-comments-on-in-a-vitehub-app"
|
|
95
|
+
},
|
|
96
|
+
COMMENTS_B0004: {
|
|
97
|
+
why: ({ file }) => `The \`database\` option of defineComments() in ${file} is not a string literal. The build reads it without running the file, so Comments would use the default Database.`,
|
|
98
|
+
fix: "Write the Database name as a string literal, such as `defineComments({ database: \"content\" })`, and put no spread after it. Remove the option to use the default or only Database."
|
|
99
|
+
},
|
|
100
|
+
COMMENTS_GITHUB_CREDENTIALS_MISSING: {
|
|
101
|
+
why: "Comments needs GitHub credentials to post to pull requests: VITEHUB_GITHUB_APP_ID with VITEHUB_GITHUB_PRIVATE_KEY, or VITEHUB_GITHUB_TOKEN.",
|
|
102
|
+
fix: "Set `VITEHUB_GITHUB_APP_ID` and `VITEHUB_GITHUB_PRIVATE_KEY` of a GitHub App that is installed on the repository, or set `VITEHUB_GITHUB_TOKEN`."
|
|
103
|
+
},
|
|
104
|
+
COMMENTS_GITHUB_REQUEST_FAILED: {
|
|
105
|
+
why: ({ path, status }) => `GitHub GET ${path} failed with ${status}`,
|
|
106
|
+
fix: "Sign in with GitHub again, because a status of 401 means that the token expired. For other statuses, check that the GitHub OAuth app of the Comments login is active and that GitHub is reachable."
|
|
107
|
+
},
|
|
108
|
+
COMMENTS_GITHUB_SYNC_FAILED: {
|
|
109
|
+
why: ({ reason, request, status }) => `GitHub ${request} failed with ${status}: ${reason}`,
|
|
110
|
+
fix: "Check that the GitHub App or `VITEHUB_GITHUB_TOKEN` can write pull request comments in the repository. A retry helps for a 5xx status."
|
|
111
|
+
},
|
|
112
|
+
COMMENTS_GUEST_RATE_LIMITED: {
|
|
113
|
+
why: ({ retryAfter }) => `This address sent too many guest comments${retryAfter === void 0 ? "" : `. It may write again in ${Math.ceil(retryAfter)} seconds`}.`,
|
|
114
|
+
fix: "Wait, then try again. Sign in to write without the guest limit of defineComments({ rateLimit })."
|
|
115
|
+
},
|
|
116
|
+
COMMENTS_MIGRATION_DATABASE_UNSUPPORTED: {
|
|
117
|
+
why: ({ dialect }) => dialect === "postgresql" ? "[vitehub] migrateComments() needs a Postgres Drizzle database with transaction()." : "[vitehub] migrateComments() needs a Drizzle database with batch() or transaction(), so a failure changes nothing.",
|
|
118
|
+
fix: "Pass `migrateComments()` the Drizzle database of `useDatabase()`, or of another driver with `transaction()` on Postgres, or `batch()` or `transaction()` on SQLite."
|
|
119
|
+
},
|
|
120
|
+
COMMENTS_MIGRATION_LIVE_POSTGRES: {
|
|
121
|
+
why: "[vitehub] The live-site comments model had no Postgres tables, so there is nothing to move.",
|
|
122
|
+
fix: "Use `from: \"outdated\"` for a Postgres Database. Only SQLite, libSQL, and D1 have tables of the live-site model."
|
|
123
|
+
},
|
|
124
|
+
COMMENTS_RATE_LIMIT_INVALID: {
|
|
125
|
+
why: ({ issue }) => `defineComments(): ${issue}`,
|
|
126
|
+
fix: "Pass rateLimit as { limit, window }, such as { limit: 5, window: \"1m\" }, or remove it to let guests write without a limit."
|
|
127
|
+
},
|
|
128
|
+
COMMENTS_SECRET_TOO_SHORT: {
|
|
129
|
+
why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
|
|
130
|
+
fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
//#endregion
|
|
135
|
+
export { commentsErrorDiagnostics as t };
|