@vite-hub/comments 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +79 -31
  2. package/dist/anchor.d.ts +7 -4
  3. package/dist/anchor.js +10 -5
  4. package/dist/client-diagnostics-CcFpkbAk.js +40 -0
  5. package/dist/client.d.ts +78 -3
  6. package/dist/client.js +198 -13
  7. package/dist/{console-BIz9t2cO.d.ts → console-h4KlhIik.d.ts} +97 -8
  8. package/dist/context-BqIsmYP1.js +61 -0
  9. package/dist/database/postgres.d.ts +738 -347
  10. package/dist/database/postgres.js +28 -7
  11. package/dist/{database-Cb2xjC1V.d.ts → database-CA1aHKN7.d.ts} +675 -276
  12. package/dist/database.d.ts +6 -98
  13. package/dist/database.js +2 -3
  14. package/dist/define-43mMR39K.js +89 -0
  15. package/dist/define-B3TF9zzn.d.ts +204 -0
  16. package/dist/errors-4gelGVmK.js +57 -0
  17. package/dist/errors-C6qptPoG.js +135 -0
  18. package/dist/errors-CyQyKAvy.d.ts +185 -0
  19. package/dist/fold-name-B7Zb3-MF.js +7 -0
  20. package/dist/{identity-3qtVC4rF.js → identity-CBOzgxSf.js} +7 -2
  21. package/dist/index-DNhy69Wt.d.ts +83 -0
  22. package/dist/index.d.ts +7 -7
  23. package/dist/index.js +196 -5
  24. package/dist/install-BcMPgPk_.js +1154 -0
  25. package/dist/install-W9ghhGoh.d.ts +36 -0
  26. package/dist/installed-B-PfERBU.js +30 -0
  27. package/dist/invariant-D8_xBqmZ.js +22 -0
  28. package/dist/migrate-B0k_0swk.d.ts +54 -0
  29. package/dist/migrate-BDQ8xqUs.js +289 -0
  30. package/dist/object-Da1zyPCR.js +11 -0
  31. package/dist/{operations-0B0QTVWX.d.ts → operations-D4A1Fcgf.d.ts} +37 -15
  32. package/dist/operations-DMMIfYPW.js +1159 -0
  33. package/dist/operations-GLeOqgMt.d.ts +257 -0
  34. package/dist/operations.d.ts +3 -7
  35. package/dist/operations.js +3 -2
  36. package/dist/overlay/client-DmsSMOzi.js +4 -0
  37. package/dist/overlay/dist-BoHMOFax.js +14 -0
  38. package/dist/overlay/dist-yIZmvSaU.js +1 -0
  39. package/dist/overlay/overlay.js +183 -177
  40. package/dist/page/loader.js +138 -18
  41. package/dist/{page-BuroSMXO.js → page-B41ozN63.js} +8 -6
  42. package/dist/{page-BtXADR6d.d.ts → page-DtbMOEMd.d.ts} +6 -5
  43. package/dist/page-tools-shared-NHUjKI8E.js +117 -0
  44. package/dist/path--zk6PEMz.js +18 -0
  45. package/dist/plugin-PS8PMYus.js +74 -0
  46. package/dist/realtime.d.ts +6 -12
  47. package/dist/realtime.js +23 -24
  48. package/dist/rpc-HBcWtg0T.d.ts +17 -0
  49. package/dist/rpc-RKPAusHp.js +153 -0
  50. package/dist/rpc.d.ts +2 -29
  51. package/dist/rpc.js +2 -75
  52. package/dist/runtime/auth.d.ts +5 -3
  53. package/dist/runtime/auth.js +8 -5
  54. package/dist/runtime/console.d.ts +1 -1
  55. package/dist/runtime/console.js +26 -21
  56. package/dist/runtime/index.d.ts +108 -60
  57. package/dist/runtime/index.js +684 -236
  58. package/dist/{server-BomGg3Gb.js → server-D8k-0GXe.js} +16 -7
  59. package/dist/server.d.ts +14 -88
  60. package/dist/server.js +7 -326
  61. package/dist/service-CFVm23k7.d.ts +158 -0
  62. package/dist/service-GHhhyQj4.js +609 -0
  63. package/dist/session-DVx-1Tym.d.ts +14 -0
  64. package/dist/session-EkudzUmm.js +503 -0
  65. package/dist/testing.d.ts +1 -1
  66. package/dist/testing.js +14 -2
  67. package/dist/tokens-DSbwkVSy.js +58 -0
  68. package/dist/types-BIS0hCEl.d.ts +124 -0
  69. package/dist/types-CZujrMFd.d.ts +322 -0
  70. package/dist/vite.d.ts +91 -87
  71. package/dist/vite.js +535 -796
  72. package/package.json +24 -27
  73. package/dist/database-BSnVrwHn.js +0 -60
  74. package/dist/database-C-ktS9Do.js +0 -95
  75. package/dist/define-BzW2Ychn.d.ts +0 -46
  76. package/dist/define-Cbhl6QVJ.js +0 -32
  77. package/dist/errors-BAQYcy3_.d.ts +0 -89
  78. package/dist/errors-DeD6wTCl.js +0 -77
  79. package/dist/h3-v1-request-DDGXJ9E7.js +0 -166
  80. package/dist/index-DklG2Etf.d.ts +0 -111
  81. package/dist/operations-NZG5dB8y.js +0 -732
  82. package/dist/page-tools-shared-D-amu6sx.js +0 -53
  83. package/dist/plugin-QElKQYkA.js +0 -725
  84. package/dist/request-DVc3M_AG.js +0 -14
  85. package/dist/src-CRTwnaEG.js +0 -1362
  86. package/dist/types-Cj8K7Vx7.d.ts +0 -176
  87. package/dist/types-Un2dcJWD.d.ts +0 -288
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/comments",
3
- "version": "0.1.0",
3
+ "version": "0.3.1",
4
4
  "description": "Comments and in-place edits on live ViteHub sites, with presence and Content drafts.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -54,11 +54,6 @@
54
54
  "import": "./dist/database/postgres.js",
55
55
  "default": "./dist/database/postgres.js"
56
56
  },
57
- "./operations": {
58
- "types": "./dist/operations.d.ts",
59
- "import": "./dist/operations.js",
60
- "default": "./dist/operations.js"
61
- },
62
57
  "./realtime": {
63
58
  "types": "./dist/realtime.d.ts",
64
59
  "import": "./dist/realtime.js",
@@ -89,11 +84,6 @@
89
84
  "import": "./dist/runtime/connect/node.js",
90
85
  "default": "./dist/runtime/connect/node.js"
91
86
  },
92
- "./runtime/console": {
93
- "types": "./dist/runtime/console.d.ts",
94
- "import": "./dist/runtime/console.js",
95
- "default": "./dist/runtime/console.js"
96
- },
97
87
  "./server": {
98
88
  "types": "./dist/server.d.ts",
99
89
  "import": "./dist/server.js",
@@ -114,33 +104,39 @@
114
104
  "dependencies": {
115
105
  "@standard-schema/spec": "^1.1.0",
116
106
  "@valibot/to-json-schema": "^1.8.0",
117
- "nostics": "1.3.0",
107
+ "nostics": "1.4.0",
118
108
  "valibot": "^1.5.0",
119
- "@vite-hub/auth": "0.1.0",
120
- "@vite-hub/forge": "0.1.0",
121
- "@vite-hub/realtime": "0.1.0",
122
- "@vite-hub/runtime": "0.1.0",
109
+ "@vite-hub/auth": "0.3.1",
110
+ "@vite-hub/forge": "0.3.1",
111
+ "@vite-hub/realtime": "0.3.1",
112
+ "@vite-hub/runtime": "0.3.1",
113
+ "birpc": "^4.2.0",
123
114
  "confbox": "^0.3.1",
124
- "drizzle-orm": "^0.45.3",
125
- "h3": "2.0.1-rc.33",
126
- "nitro": "3.0.260903-beta"
115
+ "h3": "^2.0.8"
127
116
  },
128
117
  "devDependencies": {
129
118
  "@types/node": "^24.19.1",
119
+ "@vite-hub/internal": "0.0.1",
130
120
  "happy-dom": "21.0.3",
131
121
  "marked": "17.0.6",
122
+ "modern-screenshot": "4.7.0",
123
+ "nitro": "^3.0.261103-rc",
124
+ "playwright-core": "^1.63.0",
132
125
  "publint": "^0.3.25",
133
126
  "typescript": "^6.0.3",
134
127
  "vite-plus": "^0.3.3",
135
128
  "vitest": "^4.1.11",
129
+ "vue": "3.5.44",
136
130
  "@libsql/client": "^0.18.0",
137
- "@vite-hub/database": "0.1.0",
131
+ "@vite-hub/database": "0.3.1",
138
132
  "vite": "^8.2.2",
139
- "@vite-hub/internal": "0.0.1"
133
+ "drizzle-orm": "1.0.0-rc.5"
140
134
  },
141
135
  "peerDependencies": {
142
- "@vite-hub/database": "0.1.0",
143
- "vite": ">=8.0.0"
136
+ "@vite-hub/database": "0.3.1",
137
+ "nitro": "3.0.261102-rc || ^3.0.261103-rc",
138
+ "vite": ">=8.0.0",
139
+ "drizzle-orm": "1.0.0-rc.5 || ^1.0.0"
144
140
  },
145
141
  "peerDependenciesMeta": {
146
142
  "vite": {
@@ -148,12 +144,13 @@
148
144
  }
149
145
  },
150
146
  "engines": {
151
- "node": ">=24.15.0"
147
+ "node": ">=22.22.0"
152
148
  },
153
149
  "scripts": {
154
- "build": "vp pack",
155
- "dev": "vp pack --watch",
150
+ "build": "vp pack && vp build --config overlay.vite.config.ts",
151
+ "dev": "vp pack && vp build --config overlay.vite.config.ts && vp pack --watch --no-clean",
156
152
  "typecheck": "vp run --cache -t @vite-hub/comments#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
157
- "test": "vp run -t @vite-hub/comments#build && vp test"
153
+ "test": "vp run --cache -t @vite-hub/comments#build && vp test",
154
+ "test:browser": "vp run --cache -t @vite-hub/comments#build && node --test test/browser/overlay.browser.mjs test/browser/presence.browser.mjs"
158
155
  }
159
156
  }
@@ -1,60 +0,0 @@
1
- import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
2
- //#region src/operations-core/database.ts
3
- /**
4
- * Threads of comments. `n` is unique inside `scope`, which is what `?comment=<n>` names. `anchor`, `actor`, and
5
- * `resolvedBy` hold JSON. Times are milliseconds since the epoch.
6
- */
7
- const commentThreads = sqliteTable("vitehub_comment_threads", {
8
- id: text("id").primaryKey(),
9
- scope: text("scope").notNull(),
10
- n: integer("n").notNull(),
11
- subjectKind: text("subject_kind").notNull(),
12
- subjectId: text("subject_id").notNull(),
13
- anchor: text("anchor").notNull(),
14
- status: text("status", { enum: ["open", "resolved"] }).notNull(),
15
- resolvedBy: text("resolved_by"),
16
- resolvedAt: integer("resolved_at"),
17
- authorId: text("author_id").notNull(),
18
- authorName: text("author_name"),
19
- authorImage: text("author_image"),
20
- actor: text("actor"),
21
- createdAt: integer("created_at").notNull(),
22
- updatedAt: integer("updated_at").notNull()
23
- }, (table) => [
24
- uniqueIndex("vitehub_comment_threads_scope_n").on(table.scope, table.n),
25
- index("vitehub_comment_threads_subject").on(table.subjectKind, table.subjectId),
26
- index("vitehub_comment_threads_status").on(table.status, table.updatedAt)
27
- ]);
28
- /** One Markdown message. The first message of a thread is the comment. `mentions` and `attachments` hold JSON lists. */
29
- const commentMessages = sqliteTable("vitehub_comment_messages", {
30
- id: text("id").primaryKey(),
31
- threadId: text("thread_id").notNull(),
32
- body: text("body").notNull(),
33
- authorId: text("author_id").notNull(),
34
- authorName: text("author_name"),
35
- authorImage: text("author_image"),
36
- actor: text("actor"),
37
- mentions: text("mentions").notNull(),
38
- attachments: text("attachments").notNull(),
39
- createdAt: integer("created_at").notNull(),
40
- editedAt: integer("edited_at")
41
- }, (table) => [index("vitehub_comment_messages_thread").on(table.threadId, table.createdAt)]);
42
- /**
43
- * The next thread number of each scope. A number is handed out once, so a deleted thread never gives its number to a
44
- * new one, and a link such as `?comment=3` keeps naming the same thread.
45
- */
46
- const commentCounters = sqliteTable("vitehub_comment_counters", {
47
- scope: text("scope").primaryKey(),
48
- next: integer("next").notNull()
49
- });
50
- /**
51
- * The tables behind the comment operations, for SQLite, libSQL, and D1. Add them to a Database Definition yourself
52
- * and apply their migration, or let `hubComments()` contribute them. For Postgres use `@vite-hub/comments/database/postgres`.
53
- */
54
- const commentsSchema = {
55
- commentThreads,
56
- commentMessages,
57
- commentCounters
58
- };
59
- //#endregion
60
- export { commentsSchema as i, commentMessages as n, commentThreads as r, commentCounters as t };
@@ -1,95 +0,0 @@
1
- import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
2
- //#region src/tables.ts
3
- /**
4
- * The tables of `commentsSchema` as SQLite statements that are safe to run on every start. A database that Comments
5
- * opens itself gets them on first use; a ViteHub Database gets the same tables from `vitehub db generate` instead.
6
- */
7
- const commentsTables = [
8
- "CREATE TABLE IF NOT EXISTS `vitehub_comment_threads` (`id` text PRIMARY KEY NOT NULL, `scope` text DEFAULT 'pages' NOT NULL, `number` integer DEFAULT 0 NOT NULL, `page` text NOT NULL, `anchor` text NOT NULL, `context` text, `metadata` text, `status` text NOT NULL, `created_by` text NOT NULL, `resolved_by` text, `resolved_at` integer, `created_at` integer NOT NULL, `updated_at` integer NOT NULL)",
9
- "CREATE INDEX IF NOT EXISTS `vitehub_comment_threads_page` ON `vitehub_comment_threads` (`page`,`status`)",
10
- "CREATE UNIQUE INDEX IF NOT EXISTS `vitehub_comment_threads_number` ON `vitehub_comment_threads` (`scope`,`number`)",
11
- "CREATE INDEX IF NOT EXISTS `vitehub_comment_threads_updated` ON `vitehub_comment_threads` (`updated_at`)",
12
- "CREATE TABLE IF NOT EXISTS `vitehub_comment_scope_counters` (`scope` text PRIMARY KEY NOT NULL, `last_number` integer NOT NULL)",
13
- "INSERT INTO `vitehub_comment_scope_counters` (`scope`, `last_number`) SELECT `scope`, max(`number`) FROM `vitehub_comment_threads` GROUP BY `scope` ON CONFLICT (`scope`) DO UPDATE SET `last_number` = max(`last_number`, excluded.`last_number`)",
14
- "CREATE TABLE IF NOT EXISTS `vitehub_comments` (`id` text PRIMARY KEY NOT NULL, `thread_id` text NOT NULL, `body` text NOT NULL, `mentions` text NOT NULL, `author` text NOT NULL, `created_at` integer NOT NULL, `edited_at` integer, FOREIGN KEY (`thread_id`) REFERENCES `vitehub_comment_threads`(`id`) ON UPDATE no action ON DELETE cascade)",
15
- "CREATE INDEX IF NOT EXISTS `vitehub_comments_thread` ON `vitehub_comments` (`thread_id`,`created_at`)",
16
- "CREATE TABLE IF NOT EXISTS `vitehub_comment_forge` (`id` text PRIMARY KEY NOT NULL, `thread_id` text, `repository` text NOT NULL, `pull_request` integer NOT NULL, `remote_id` text, `node_id` text, `url` text, `digest` text, `posted_as` text, `minimized` integer DEFAULT false NOT NULL, `error` text, `updated_at` integer NOT NULL)",
17
- "CREATE INDEX IF NOT EXISTS `vitehub_comment_forge_thread` ON `vitehub_comment_forge` (`thread_id`)",
18
- "CREATE INDEX IF NOT EXISTS `vitehub_comment_forge_pull_request` ON `vitehub_comment_forge` (`repository`,`pull_request`)"
19
- ];
20
- //#endregion
21
- //#region src/database.ts
22
- const commentThreads = sqliteTable("vitehub_comment_threads", {
23
- id: text("id").primaryKey(),
24
- /** `pages` for the overlay, or the scope that app code picks. */
25
- scope: text("scope").notNull().default("pages"),
26
- /** Counts up from 1 in each scope. */
27
- number: integer("number").notNull().default(0),
28
- /** Normalized pathname, such as `/pricing`. */
29
- page: text("page").notNull(),
30
- /** JSON of the anchor, `null` for threads that app code anchors itself. */
31
- anchor: text("anchor").notNull(),
32
- /** JSON of the page, element, components, browser, and build. */
33
- context: text("context"),
34
- /** JSON of the fields that app code keeps on the thread. */
35
- metadata: text("metadata"),
36
- status: text("status", { enum: ["open", "resolved"] }).notNull(),
37
- /** JSON of the author who opened the thread. */
38
- createdBy: text("created_by").notNull(),
39
- resolvedBy: text("resolved_by"),
40
- resolvedAt: integer("resolved_at"),
41
- /** Milliseconds since the epoch. */
42
- createdAt: integer("created_at").notNull(),
43
- /** The last comment, resolve, or reopen. */
44
- updatedAt: integer("updated_at").notNull()
45
- }, (table) => [
46
- index("vitehub_comment_threads_page").on(table.page, table.status),
47
- uniqueIndex("vitehub_comment_threads_number").on(table.scope, table.number),
48
- index("vitehub_comment_threads_updated").on(table.updatedAt)
49
- ]);
50
- /**
51
- * The tables behind Comments, including forge links and scope numbering. ViteHub adds them to the Database of
52
- * `defineComments({ database })` for you; add them yourself only to a Database configured without ViteHub.
53
- * For existing tables, follow https://vitehub.dev/docs/comments/configure#upgrade-existing-comments before
54
- * applying the migration that `vitehub db generate` writes.
55
- */
56
- const commentsSchema = {
57
- vitehubCommentThreads: commentThreads,
58
- vitehubComments: sqliteTable("vitehub_comments", {
59
- id: text("id").primaryKey(),
60
- threadId: text("thread_id").notNull().references(() => commentThreads.id, { onDelete: "cascade" }),
61
- body: text("body").notNull(),
62
- /** JSON array of `{ id, name }`. */
63
- mentions: text("mentions").notNull(),
64
- /** JSON of the author. */
65
- author: text("author").notNull(),
66
- createdAt: integer("created_at").notNull(),
67
- editedAt: integer("edited_at")
68
- }, (table) => [index("vitehub_comments_thread").on(table.threadId, table.createdAt)]),
69
- vitehubCommentForge: sqliteTable("vitehub_comment_forge", {
70
- /** A comment id, `summary:<repository>#<pull request>`, or `cleanup:<repository>#<remote id>` for a pending delete. */
71
- id: text("id").primaryKey(),
72
- /** Null for summaries and cleanup rows, which survive deletion of the original thread. */
73
- threadId: text("thread_id"),
74
- repository: text("repository").notNull(),
75
- pullRequest: integer("pull_request").notNull(),
76
- /** The forge's id of the comment. Null until it posts. */
77
- remoteId: text("remote_id"),
78
- /** The GraphQL id, to hide the comment of a resolved thread. */
79
- nodeId: text("node_id"),
80
- url: text("url"),
81
- /** Hash of the body the forge has, so an unchanged comment is not sent again. */
82
- digest: text("digest"),
83
- postedAs: text("posted_as", { enum: ["author", "app"] }),
84
- /** Whether the forge hides the comment, because its thread is resolved. */
85
- minimized: integer("minimized", { mode: "boolean" }).notNull().default(false),
86
- error: text("error"),
87
- updatedAt: integer("updated_at").notNull()
88
- }, (table) => [index("vitehub_comment_forge_thread").on(table.threadId), index("vitehub_comment_forge_pull_request").on(table.repository, table.pullRequest)]),
89
- vitehubCommentScopeCounters: sqliteTable("vitehub_comment_scope_counters", {
90
- scope: text("scope").primaryKey(),
91
- lastNumber: integer("last_number").notNull()
92
- })
93
- };
94
- //#endregion
95
- export { commentsTables as n, commentsSchema as t };
@@ -1,46 +0,0 @@
1
- import { _ as CommentUser, d as CommentMessage, g as CommentThread, h as CommentSubject, n as CommentActor } from "./types-Cj8K7Vx7.js";
2
- //#region src/operations-core/define.d.ts
3
- type CommentAction = "read" | "write" | "resolve" | "delete";
4
- interface CommentsAuthorizeContext {
5
- /** The signed-in user, including application fields such as `role`, or null. */
6
- user: (CommentUser & Record<string, unknown>) | null;
7
- /** The Agent Actor when an agent acts for `user`. */
8
- actor?: CommentActor;
9
- action: CommentAction;
10
- /** The thread that the action is about. Not set for `create`, `list`, and `users`. */
11
- thread?: CommentThread;
12
- /**
13
- * What the action is about: the subject of `thread`, the subject that `create` starts a thread on, or the subject
14
- * that a `list` filters by. Not set for a `list` with no filter and for `users`.
15
- */
16
- subject?: CommentSubject;
17
- }
18
- /** Decides whether a person or an Agent may take an action. Comments are private: without it, nobody can read. */
19
- type CommentsAuthorize = (context: CommentsAuthorizeContext) => boolean | Promise<boolean>;
20
- /** A kind of subject that threads can be about. */
21
- interface CommentSubjectDefinition {
22
- kind: string;
23
- /** The numbering scope of a subject id. `n` is unique inside a scope. */
24
- scope: (subjectId: string) => string;
25
- }
26
- interface CommentMentionEvent {
27
- thread: CommentThread;
28
- message: CommentMessage;
29
- /** The users that this message mentions for the first time. */
30
- mentioned: CommentUser[];
31
- }
32
- interface CommentsDefinition {
33
- authorize?: CommentsAuthorize;
34
- /** Subject kinds in addition to `page` (scope `site`) and `content` (scope `site`). */
35
- subjects?: readonly CommentSubjectDefinition[];
36
- /** Runs after a message that mentions someone is saved. A failure is logged and never fails the comment. */
37
- onMention?: (event: CommentMentionEvent) => void | Promise<void>;
38
- }
39
- /** Validate the imported application module before installing its runtime. */
40
- declare function validateCommentsDefinition(value: unknown, file: string): CommentsDefinition;
41
- /** A subject kind of your own, such as `drop`. */
42
- declare function defineCommentSubject(subject: CommentSubjectDefinition): CommentSubjectDefinition;
43
- /** Subjects that exist without a definition. */
44
- declare const builtinCommentSubjects: readonly CommentSubjectDefinition[];
45
- //#endregion
46
- export { CommentsAuthorizeContext as a, defineCommentSubject as c, CommentsAuthorize as i, validateCommentsDefinition as l, CommentMentionEvent as n, CommentsDefinition as o, CommentSubjectDefinition as r, builtinCommentSubjects as s, CommentAction as t };
@@ -1,32 +0,0 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-DeD6wTCl.js";
2
- //#region src/operations-core/define.ts
3
- const marker = Symbol.for("vitehub.comments.definition");
4
- /** The definition that `server/comments.ts` default-exports. */
5
- function defineComments(definition = {}) {
6
- return Object.freeze({
7
- ...definition,
8
- [marker]: true
9
- });
10
- }
11
- function isCommentsDefinition(value) {
12
- return value !== null && Object(value) === value && Reflect.get(Object(value), marker) === true;
13
- }
14
- /** Validate the imported application module before installing its runtime. */
15
- function validateCommentsDefinition(value, file) {
16
- if (!isCommentsDefinition(value)) throw commentsErrorDiagnostics.COMMENTS_B0002({ file });
17
- return value;
18
- }
19
- /** A subject kind of your own, such as `drop`. */
20
- function defineCommentSubject(subject) {
21
- return Object.freeze({ ...subject });
22
- }
23
- /** Subjects that exist without a definition. */
24
- const builtinCommentSubjects = [defineCommentSubject({
25
- kind: "page",
26
- scope: () => "site"
27
- }), defineCommentSubject({
28
- kind: "content",
29
- scope: () => "site"
30
- })];
31
- //#endregion
32
- export { validateCommentsDefinition as i, defineCommentSubject as n, defineComments as r, builtinCommentSubjects as t };
@@ -1,89 +0,0 @@
1
- //#region src/operations-core/errors.d.ts
2
- declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
3
- readonly COMMENTS_R0001: {
4
- readonly why: ({ target }: {
5
- target: string;
6
- }) => string;
7
- readonly fix: "Pass an element, a non-empty selection, or a point that is over an element of the page.";
8
- };
9
- readonly COMMENTS_R0002: {
10
- readonly why: ({ id }: {
11
- id: string;
12
- }) => string;
13
- readonly fix: "List the threads again, because someone may have deleted this one.";
14
- };
15
- readonly COMMENTS_R0003: {
16
- readonly why: ({ messageId }: {
17
- messageId: string;
18
- }) => string;
19
- readonly fix: "Read the thread again, because someone may have deleted the message.";
20
- };
21
- readonly COMMENTS_R0004: {
22
- readonly why: "Only the author of a message can edit or delete it.";
23
- readonly fix: "Sign in as the author, or ask them to change the message.";
24
- };
25
- readonly COMMENTS_R0005: {
26
- readonly why: "A comment needs some text.";
27
- readonly fix: "Write at least one character before you send.";
28
- };
29
- readonly COMMENTS_R0006: {
30
- readonly why: "server/comments.ts defines no authorize policy, so nobody can read or write comments.";
31
- readonly fix: "Pass authorize to defineComments({ authorize }) and return true for the people and Agents that may take the action.";
32
- };
33
- readonly COMMENTS_R0007: {
34
- readonly why: ({ message }: {
35
- message: string;
36
- }) => string;
37
- readonly fix: "Mention only people that users() finds, and write @ and their name in the text.";
38
- };
39
- readonly COMMENTS_R0008: {
40
- readonly why: ({ kind }: {
41
- kind: string;
42
- }) => string;
43
- readonly fix: "Use page or content, or add defineCommentSubject({ kind, scope }) to defineComments({ subjects }).";
44
- };
45
- readonly COMMENTS_R0009: {
46
- readonly why: ({ action }: {
47
- action: string;
48
- }) => string;
49
- readonly fix: "Ask for access, or allow the action in defineComments({ authorize }).";
50
- };
51
- readonly COMMENTS_R0010: {
52
- readonly why: "The comments runtime is not installed.";
53
- readonly fix: "Add server/comments.ts and enable the Database with vitehub({ database: true }). `vite dev` and builds install the runtime for you.";
54
- };
55
- readonly COMMENTS_R0011: {
56
- readonly why: "The comment numbers of this scope are busy.";
57
- readonly fix: "Try again. Several people created a comment at the same moment.";
58
- };
59
- readonly COMMENTS_R0012: {
60
- readonly why: "Writing a comment needs a signed-in user.";
61
- readonly fix: "Sign in, then try again. In `vite dev` without sign-in, set console.auth so comments know who writes.";
62
- };
63
- readonly COMMENTS_R0013: {
64
- readonly why: "The comments request did not get an answer from the server.";
65
- readonly fix: "Check the connection and the app URL, then try again.";
66
- };
67
- readonly COMMENTS_R0014: {
68
- readonly why: "Attachments are not supported yet: no operation uploads a file for a comment.";
69
- readonly fix: "Send the comment without attachments. They arrive with the upload operation.";
70
- };
71
- readonly COMMENTS_R0015: {
72
- readonly why: "The comment list kept changing while its pages were loading.";
73
- readonly fix: "Refresh again. The previous cache is kept until two complete scans agree.";
74
- };
75
- readonly COMMENTS_B0001: {
76
- readonly why: ({ file }: {
77
- file: string;
78
- }) => string;
79
- readonly fix: "Remove `database: false` from vitehub(), or set `database: true`. vitehub() turns the Database on for comments when the option is unset.";
80
- };
81
- readonly COMMENTS_B0002: {
82
- readonly why: ({ file }: {
83
- file: string;
84
- }) => string;
85
- readonly fix: "Write `export default defineComments({ authorize })` in server/comments.ts.";
86
- };
87
- }, readonly import("nostics").AnyDiagnosticReporter[], never>;
88
- //#endregion
89
- export { commentsErrorDiagnostics as t };
@@ -1,77 +0,0 @@
1
- import { defineDiagnostics } from "nostics";
2
- //#region src/operations-core/errors.ts
3
- const commentsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
4
- docsBase: () => "https://vitehub.dev/docs/reference/diagnostics",
5
- codes: {
6
- COMMENTS_R0001: {
7
- why: ({ target }) => `createAnchor() found nothing to anchor to for ${target}.`,
8
- fix: "Pass an element, a non-empty selection, or a point that is over an element of the page."
9
- },
10
- COMMENTS_R0002: {
11
- why: ({ id }) => `The comment thread "${id}" does not exist.`,
12
- fix: "List the threads again, because someone may have deleted this one."
13
- },
14
- COMMENTS_R0003: {
15
- why: ({ messageId }) => `The comment message "${messageId}" does not exist in this thread.`,
16
- fix: "Read the thread again, because someone may have deleted the message."
17
- },
18
- COMMENTS_R0004: {
19
- why: "Only the author of a message can edit or delete it.",
20
- fix: "Sign in as the author, or ask them to change the message."
21
- },
22
- COMMENTS_R0005: {
23
- why: "A comment needs some text.",
24
- fix: "Write at least one character before you send."
25
- },
26
- COMMENTS_R0006: {
27
- why: "server/comments.ts defines no authorize policy, so nobody can read or write comments.",
28
- fix: "Pass authorize to defineComments({ authorize }) and return true for the people and Agents that may take the action."
29
- },
30
- COMMENTS_R0007: {
31
- why: ({ message }) => message,
32
- fix: "Mention only people that users() finds, and write @ and their name in the text."
33
- },
34
- COMMENTS_R0008: {
35
- why: ({ kind }) => `The comment subject kind "${kind}" is not defined.`,
36
- fix: "Use page or content, or add defineCommentSubject({ kind, scope }) to defineComments({ subjects })."
37
- },
38
- COMMENTS_R0009: {
39
- why: ({ action }) => `This user or Agent may not ${action} this comment.`,
40
- fix: "Ask for access, or allow the action in defineComments({ authorize })."
41
- },
42
- COMMENTS_R0010: {
43
- why: "The comments runtime is not installed.",
44
- fix: "Add server/comments.ts and enable the Database with vitehub({ database: true }). `vite dev` and builds install the runtime for you."
45
- },
46
- COMMENTS_R0011: {
47
- why: "The comment numbers of this scope are busy.",
48
- fix: "Try again. Several people created a comment at the same moment."
49
- },
50
- COMMENTS_R0012: {
51
- why: "Writing a comment needs a signed-in user.",
52
- fix: "Sign in, then try again. In `vite dev` without sign-in, set console.auth so comments know who writes."
53
- },
54
- COMMENTS_R0013: {
55
- why: "The comments request did not get an answer from the server.",
56
- fix: "Check the connection and the app URL, then try again."
57
- },
58
- COMMENTS_R0014: {
59
- why: "Attachments are not supported yet: no operation uploads a file for a comment.",
60
- fix: "Send the comment without attachments. They arrive with the upload operation."
61
- },
62
- COMMENTS_R0015: {
63
- why: "The comment list kept changing while its pages were loading.",
64
- fix: "Refresh again. The previous cache is kept until two complete scans agree."
65
- },
66
- COMMENTS_B0001: {
67
- why: ({ file }) => `${file} needs a Database, but the Database is off for this app.`,
68
- fix: "Remove `database: false` from vitehub(), or set `database: true`. vitehub() turns the Database on for comments when the option is unset."
69
- },
70
- COMMENTS_B0002: {
71
- why: ({ file }) => `${file} must default-export defineComments().`,
72
- fix: "Write `export default defineComments({ authorize })` in server/comments.ts."
73
- }
74
- }
75
- });
76
- //#endregion
77
- export { commentsErrorDiagnostics as t };
@@ -1,166 +0,0 @@
1
- //#region ../internal/src/runtime/h3-v1-request.ts
2
- const payloadMethods = /* @__PURE__ */ new Set([
3
- "DELETE",
4
- "PATCH",
5
- "POST",
6
- "PUT"
7
- ]);
8
- const rawBodySymbol = Symbol.for("h3RawBody");
9
- const nodeEventRequests = /* @__PURE__ */ new WeakMap();
10
- /** Return true for an event with an own `node.req` object, such as an H3 1 event. */
11
- function isH3V1Event(input) {
12
- if (!Object.hasOwn(input, "node")) return false;
13
- const node = Reflect.get(input, "node");
14
- return isObjectLike(node) && isObjectLike(Reflect.get(node, "req"));
15
- }
16
- function isObjectLike(value) {
17
- return value !== null && (typeof value === "object" || typeof value === "function");
18
- }
19
- function isWebRequest(value) {
20
- if (!isObjectLike(value)) return false;
21
- const headers = Reflect.get(value, "headers");
22
- return typeof Reflect.get(value, "url") === "string" && typeof Reflect.get(value, "method") === "string" && isObjectLike(headers) && typeof Reflect.get(headers, "get") === "function";
23
- }
24
- function firstHeader(value) {
25
- return Array.isArray(value) ? value[0] : value;
26
- }
27
- function readNodeRequestHeaders(request) {
28
- const headers = new Headers();
29
- for (const [name, value] of Object.entries(request.headers)) if (Array.isArray(value)) for (const item of value) headers.append(name, item);
30
- else if (value !== void 0) headers.set(name, value);
31
- return headers;
32
- }
33
- /** Rebuild the public URL. H3 1 removes the app base path from `url` and keeps it in `originalUrl`. */
34
- function readNodeRequestURL(request) {
35
- const host = firstHeader(request.headers.host) || "localhost";
36
- const encrypted = request.socket?.encrypted || request.connection?.encrypted;
37
- const protocol = firstHeader(request.headers["x-forwarded-proto"]) === "https" || encrypted ? "https" : "http";
38
- const path = (request.originalUrl || request.url || "/").replace(/^[/\\]+/, "/");
39
- return new URL(path, `${protocol}://${host}`);
40
- }
41
- function toBodyStream(value) {
42
- if (value instanceof ReadableStream) return value;
43
- if (value instanceof Uint8Array) return new ReadableStream({ start(controller) {
44
- controller.enqueue(value);
45
- controller.close();
46
- } });
47
- if (typeof value === "string") return new Blob([value]).stream();
48
- if (value instanceof URLSearchParams) return new Blob([value.toString()]).stream();
49
- if (value instanceof Object && Object.getPrototypeOf(value) === Object.prototype) return new Blob([JSON.stringify(value)]).stream();
50
- }
51
- async function openNodeRequestBody(event) {
52
- const request = event.node.req;
53
- const stored = event._requestBody ?? request[rawBodySymbol] ?? request.rawBody ?? request.body;
54
- if (stored !== void 0 && stored !== null) {
55
- const stream = toBodyStream(await stored);
56
- if (stream) {
57
- const reader = stream.getReader();
58
- return () => reader.read();
59
- }
60
- }
61
- const iterator = request[Symbol.asyncIterator]?.();
62
- if (!iterator) return void 0;
63
- const chunks = [];
64
- const collected = [];
65
- let total = 0;
66
- let ended = false;
67
- let failed = false;
68
- let failure;
69
- let waiting;
70
- const produce = async () => {
71
- try {
72
- for await (const chunk of { [Symbol.asyncIterator]: () => iterator }) {
73
- let bytes;
74
- if (typeof chunk === "string") bytes = new TextEncoder().encode(chunk);
75
- else if (chunk instanceof Uint8Array) bytes = chunk;
76
- else throw new TypeError("[vitehub] Request body chunks must be strings or bytes.");
77
- collected.push(bytes);
78
- total += bytes.byteLength;
79
- if (waiting) {
80
- waiting.resolve({ value: bytes });
81
- waiting = void 0;
82
- } else chunks.push(bytes);
83
- }
84
- ended = true;
85
- waiting?.resolve({ done: true });
86
- waiting = void 0;
87
- } catch (error) {
88
- failed = true;
89
- failure = error;
90
- ended = true;
91
- waiting?.reject(error);
92
- waiting = void 0;
93
- throw error;
94
- }
95
- const bytes = new Uint8Array(total);
96
- let offset = 0;
97
- for (const chunk of collected) {
98
- bytes.set(chunk, offset);
99
- offset += chunk.byteLength;
100
- }
101
- return bytes;
102
- };
103
- let body;
104
- const start = () => body ??= produce();
105
- event._requestBody = { then: (resolve, reject) => start().then(resolve, reject) };
106
- return async () => {
107
- start();
108
- body?.catch(() => {});
109
- if (failed) throw failure;
110
- if (chunks.length) return { value: chunks.shift() };
111
- if (ended) return { done: true };
112
- return new Promise((resolve, reject) => {
113
- waiting = {
114
- resolve,
115
- reject
116
- };
117
- });
118
- };
119
- }
120
- /** Read the body lazily, from a value a host already read or from the Node request stream. */
121
- function readNodeRequestBody(event) {
122
- let reader;
123
- return new ReadableStream({ async pull(controller) {
124
- const chunk = await (await (reader ??= openNodeRequestBody(event)))?.();
125
- if (!chunk || chunk.done) {
126
- controller.close();
127
- return;
128
- }
129
- const value = chunk.value;
130
- if (typeof value === "string") controller.enqueue(new TextEncoder().encode(value));
131
- else if (value instanceof Uint8Array) controller.enqueue(value);
132
- else controller.error(/* @__PURE__ */ new TypeError("[vitehub] Request body chunks must be strings or bytes."));
133
- } }, { highWaterMark: 0 });
134
- }
135
- /** Return one Web Request per H3 1 event. The body is read only when a caller reads the Request body. */
136
- function toH3V1Request(event) {
137
- const cached = nodeEventRequests.get(event);
138
- if (cached) return cached;
139
- if (isWebRequest(event.web?.request)) return event.web.request;
140
- const request = event.node.req;
141
- const method = (request.method || "GET").toUpperCase();
142
- const init = {
143
- headers: readNodeRequestHeaders(request),
144
- method
145
- };
146
- if (payloadMethods.has(method)) {
147
- init.body = readNodeRequestBody(event);
148
- init.duplex = "half";
149
- }
150
- const webRequest = new Request(readNodeRequestURL(request), init);
151
- nodeEventRequests.set(event, webRequest);
152
- return webRequest;
153
- }
154
- /**
155
- * Return the Web Request of a request, an H3 2 event with an own `req` request, or an H3 1 event such as Nuxt 4's.
156
- * H3 1 events have no `url`, so read the URL from the request this returns. Throws a `TypeError` for any other value.
157
- */
158
- function toEventRequest(event) {
159
- if (isWebRequest(event)) return event;
160
- const req = Object.hasOwn(event, "req") ? Reflect.get(event, "req") : void 0;
161
- if (isWebRequest(req)) return req;
162
- if (isH3V1Event(event)) return toH3V1Request(event);
163
- throw new TypeError("[vitehub] Expected a Request, an H3 2 event, or an H3 1 event.");
164
- }
165
- //#endregion
166
- export { toEventRequest as n, toH3V1Request as r, isH3V1Event as t };