@vite-hub/comments 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +243 -0
  3. package/dist/anchor.d.ts +40 -0
  4. package/dist/anchor.js +128 -0
  5. package/dist/client.d.ts +101 -0
  6. package/dist/client.js +553 -0
  7. package/dist/console-BIz9t2cO.d.ts +243 -0
  8. package/dist/database/postgres.d.ts +1011 -0
  9. package/dist/database/postgres.js +60 -0
  10. package/dist/database-BSnVrwHn.js +60 -0
  11. package/dist/database-C-ktS9Do.js +95 -0
  12. package/dist/database-Cb2xjC1V.d.ts +1096 -0
  13. package/dist/database.d.ts +104 -0
  14. package/dist/database.js +3 -0
  15. package/dist/define-BzW2Ychn.d.ts +46 -0
  16. package/dist/define-Cbhl6QVJ.js +32 -0
  17. package/dist/errors-BAQYcy3_.d.ts +89 -0
  18. package/dist/errors-DeD6wTCl.js +77 -0
  19. package/dist/h3-v1-request-DDGXJ9E7.js +166 -0
  20. package/dist/identity-3qtVC4rF.js +34 -0
  21. package/dist/index-DklG2Etf.d.ts +111 -0
  22. package/dist/index.d.ts +7 -0
  23. package/dist/index.js +5 -0
  24. package/dist/operations-0B0QTVWX.d.ts +138 -0
  25. package/dist/operations-NZG5dB8y.js +732 -0
  26. package/dist/operations.d.ts +7 -0
  27. package/dist/operations.js +2 -0
  28. package/dist/overlay/overlay.js +195 -0
  29. package/dist/page/loader.js +22 -0
  30. package/dist/page-BtXADR6d.d.ts +21 -0
  31. package/dist/page-BuroSMXO.js +38 -0
  32. package/dist/page-tools-shared-D-amu6sx.js +53 -0
  33. package/dist/plugin-QElKQYkA.js +725 -0
  34. package/dist/realtime.d.ts +18 -0
  35. package/dist/realtime.js +48 -0
  36. package/dist/request-DVc3M_AG.js +14 -0
  37. package/dist/rpc.d.ts +29 -0
  38. package/dist/rpc.js +75 -0
  39. package/dist/runtime/auth.d.ts +6 -0
  40. package/dist/runtime/auth.js +15 -0
  41. package/dist/runtime/connect/node.d.ts +1 -0
  42. package/dist/runtime/connect/node.js +2 -0
  43. package/dist/runtime/connect.d.ts +1 -0
  44. package/dist/runtime/connect.js +2 -0
  45. package/dist/runtime/console.d.ts +5 -0
  46. package/dist/runtime/console.js +59 -0
  47. package/dist/runtime/index.d.ts +222 -0
  48. package/dist/runtime/index.js +665 -0
  49. package/dist/server-BomGg3Gb.js +63 -0
  50. package/dist/server.d.ts +94 -0
  51. package/dist/server.js +326 -0
  52. package/dist/src-CRTwnaEG.js +1362 -0
  53. package/dist/testing.d.ts +30 -0
  54. package/dist/testing.js +175 -0
  55. package/dist/types-Cj8K7Vx7.d.ts +176 -0
  56. package/dist/types-Un2dcJWD.d.ts +288 -0
  57. package/dist/vite.d.ts +304 -0
  58. package/dist/vite.js +1921 -0
  59. package/package.json +156 -4
@@ -0,0 +1,60 @@
1
+ import { bigint, index, pgTable, text, uniqueIndex } from "drizzle-orm/pg-core";
2
+ //#region src/operations-core/database/postgres.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 = pgTable("vitehub_comment_threads", {
8
+ id: text("id").primaryKey(),
9
+ scope: text("scope").notNull(),
10
+ n: bigint("n", { mode: "number" }).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: bigint("resolved_at", { mode: "number" }),
17
+ authorId: text("author_id").notNull(),
18
+ authorName: text("author_name"),
19
+ authorImage: text("author_image"),
20
+ actor: text("actor"),
21
+ createdAt: bigint("created_at", { mode: "number" }).notNull(),
22
+ updatedAt: bigint("updated_at", { mode: "number" }).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 = pgTable("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: bigint("created_at", { mode: "number" }).notNull(),
40
+ editedAt: bigint("edited_at", { mode: "number" })
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 = pgTable("vitehub_comment_counters", {
47
+ scope: text("scope").primaryKey(),
48
+ next: bigint("next", { mode: "number" }).notNull()
49
+ });
50
+ /**
51
+ * The tables behind the comment operations, for Postgres. Add them to a Database Definition yourself
52
+ * and apply their migration, or let `hubComments()` contribute them. For SQLite, libSQL, and D1 use `@vite-hub/comments/database`.
53
+ */
54
+ const commentsPostgresSchema = {
55
+ commentThreads,
56
+ commentMessages,
57
+ commentCounters
58
+ };
59
+ //#endregion
60
+ export { commentCounters, commentMessages, commentThreads, commentsPostgresSchema };
@@ -0,0 +1,60 @@
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 };
@@ -0,0 +1,95 @@
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 };