@vite-hub/comments 0.0.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.
Files changed (77) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +291 -0
  3. package/dist/anchor.d.ts +43 -0
  4. package/dist/anchor.js +133 -0
  5. package/dist/client-diagnostics-CcFpkbAk.js +40 -0
  6. package/dist/client.d.ts +176 -0
  7. package/dist/client.js +738 -0
  8. package/dist/console-h4KlhIik.d.ts +332 -0
  9. package/dist/context-BqIsmYP1.js +61 -0
  10. package/dist/database/postgres.d.ts +1402 -0
  11. package/dist/database/postgres.js +81 -0
  12. package/dist/database-CA1aHKN7.d.ts +1495 -0
  13. package/dist/database.d.ts +12 -0
  14. package/dist/database.js +2 -0
  15. package/dist/define-43mMR39K.js +89 -0
  16. package/dist/define-B3TF9zzn.d.ts +204 -0
  17. package/dist/errors-4gelGVmK.js +57 -0
  18. package/dist/errors-C6qptPoG.js +135 -0
  19. package/dist/errors-CyQyKAvy.d.ts +185 -0
  20. package/dist/fold-name-B7Zb3-MF.js +7 -0
  21. package/dist/identity-CBOzgxSf.js +39 -0
  22. package/dist/index-DNhy69Wt.d.ts +83 -0
  23. package/dist/index.d.ts +7 -0
  24. package/dist/index.js +196 -0
  25. package/dist/install-BcMPgPk_.js +1154 -0
  26. package/dist/install-W9ghhGoh.d.ts +36 -0
  27. package/dist/installed-B-PfERBU.js +30 -0
  28. package/dist/invariant-D8_xBqmZ.js +22 -0
  29. package/dist/migrate-B0k_0swk.d.ts +54 -0
  30. package/dist/migrate-BDQ8xqUs.js +289 -0
  31. package/dist/object-Da1zyPCR.js +11 -0
  32. package/dist/operations-D4A1Fcgf.d.ts +160 -0
  33. package/dist/operations-DMMIfYPW.js +1159 -0
  34. package/dist/operations-GLeOqgMt.d.ts +257 -0
  35. package/dist/operations.d.ts +3 -0
  36. package/dist/operations.js +3 -0
  37. package/dist/overlay/client-DmsSMOzi.js +4 -0
  38. package/dist/overlay/dist-BoHMOFax.js +14 -0
  39. package/dist/overlay/dist-yIZmvSaU.js +1 -0
  40. package/dist/overlay/overlay.js +201 -0
  41. package/dist/page/loader.js +142 -0
  42. package/dist/page-B41ozN63.js +40 -0
  43. package/dist/page-DtbMOEMd.d.ts +22 -0
  44. package/dist/page-tools-shared-NHUjKI8E.js +117 -0
  45. package/dist/path--zk6PEMz.js +18 -0
  46. package/dist/plugin-PS8PMYus.js +74 -0
  47. package/dist/realtime.d.ts +12 -0
  48. package/dist/realtime.js +47 -0
  49. package/dist/rpc-HBcWtg0T.d.ts +17 -0
  50. package/dist/rpc-RKPAusHp.js +153 -0
  51. package/dist/rpc.d.ts +2 -0
  52. package/dist/rpc.js +2 -0
  53. package/dist/runtime/auth.d.ts +8 -0
  54. package/dist/runtime/auth.js +18 -0
  55. package/dist/runtime/connect/node.d.ts +1 -0
  56. package/dist/runtime/connect/node.js +2 -0
  57. package/dist/runtime/connect.d.ts +1 -0
  58. package/dist/runtime/connect.js +2 -0
  59. package/dist/runtime/console.d.ts +5 -0
  60. package/dist/runtime/console.js +64 -0
  61. package/dist/runtime/index.d.ts +270 -0
  62. package/dist/runtime/index.js +1113 -0
  63. package/dist/server-D8k-0GXe.js +72 -0
  64. package/dist/server.d.ts +20 -0
  65. package/dist/server.js +7 -0
  66. package/dist/service-CFVm23k7.d.ts +158 -0
  67. package/dist/service-GHhhyQj4.js +609 -0
  68. package/dist/session-DVx-1Tym.d.ts +14 -0
  69. package/dist/session-EkudzUmm.js +503 -0
  70. package/dist/testing.d.ts +30 -0
  71. package/dist/testing.js +187 -0
  72. package/dist/tokens-DSbwkVSy.js +58 -0
  73. package/dist/types-BIS0hCEl.d.ts +124 -0
  74. package/dist/types-CZujrMFd.d.ts +322 -0
  75. package/dist/vite.d.ts +308 -0
  76. package/dist/vite.js +1660 -0
  77. package/package.json +153 -4
package/dist/vite.d.ts ADDED
@@ -0,0 +1,308 @@
1
+ import { a as CommentBuild } from "./types-CZujrMFd.js";
2
+ import "./types-BIS0hCEl.js";
3
+ import { a as mountedCommentsRoute } from "./page-DtbMOEMd.js";
4
+ import { n as OperationContributions } from "./operations-D4A1Fcgf.js";
5
+ import { i as ViteHubInspectionPluginMetadata, r as ViteHubConsoleRuntimeRecordTableSection, t as ViteHubConsoleOperationSection } from "./console-h4KlhIik.js";
6
+ import { Plugin, PluginOption } from "vite";
7
+ import { githubRepository } from "@vite-hub/forge/build/node";
8
+ import { DatabaseContributionContext, DatabaseContributionEntry } from "@vite-hub/database/vite";
9
+ import { NitroModule } from "nitro/types";
10
+ //#region src/console.d.ts
11
+ /**
12
+ * Console section for Comments: every thread with its first comment, page, author, replies, and status, open threads
13
+ * first. People reply and resolve on the page itself, where the context is; each record links there. The
14
+ * Console shows it when the app has `server/comments.ts`.
15
+ */
16
+ export declare const commentsConsoleSection: ViteHubConsoleRuntimeRecordTableSection<{
17
+ projectRoot: string;
18
+ serverDirs?: string[];
19
+ }>;
20
+ //#endregion
21
+ //#region ../internal/src/deployment.d.ts
22
+ /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
23
+ type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
24
+ //#endregion
25
+ //#region ../internal/src/build/deployment-plan-output.d.ts
26
+ /**
27
+ * One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
28
+ * a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
29
+ * It holds names only, so `vitehub deploy` can check the host without booting Vite. It never holds a value.
30
+ */
31
+ interface DeploymentEnvEntry {
32
+ /** The declaration path, such as `env.server.github.token`, when it is safe to show. Primitive entries have none. */
33
+ path?: string;
34
+ /** The host variable names, in read order. The first name that is set supplies the value. */
35
+ names: readonly string[];
36
+ /** Any variable whose name starts with this prefix supplies the value, such as `VITEHUB_CONSOLE_KEY_`. */
37
+ prefix?: string;
38
+ required: boolean;
39
+ secret: boolean;
40
+ /** A default supplies the value when no name is set. */
41
+ hasDefault: boolean;
42
+ /** The primitives that read these names, such as `blob`. Server Env declarations have none. */
43
+ owners?: readonly string[];
44
+ }
45
+ /** What a primitive needs to know to name the variables it reads in the deployed app. */
46
+ interface DeploymentEnvContext {
47
+ host: ViteHubHost;
48
+ }
49
+ /**
50
+ * The host variables that a primitive reads itself, outside the Server Env registry, for one host and its resolved
51
+ * config. A Vite plugin exposes it as `api.deploymentEnv`, and the build writes the result to `deployment.json`.
52
+ * Return names only, never values.
53
+ */
54
+ type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
55
+ //#endregion
56
+ //#region src/live-vite.d.ts
57
+ /** Module paths that generated files import. The `vite-hub` distribution passes its own subpaths. */
58
+ interface CommentsImports {
59
+ /** Exports `defineCommentsPlugin`, `createCommentsHandler`, and `viteHubPageSessionHandler`. */
60
+ runtime: string;
61
+ /** Exports `commentsRealtime`. */
62
+ realtime: string;
63
+ /** Exports `commentsAuthSession`. */
64
+ auth: string;
65
+ /** Exports `commentsSchema`. */
66
+ database: string;
67
+ /** Exports `databases`, the runtime Database registry. */
68
+ databases: string;
69
+ /** Exports `parseContentField`. */
70
+ contentClient: string;
71
+ /** Exports `connectDatabase`, for Workers. Its `/node` subpath also opens SQLite files. */
72
+ connect: string;
73
+ /** Exports `blob`, the Blob store that attachments go to when the app has Blob. */
74
+ blob: string;
75
+ /** Exports `checkRateLimit`, which counts guest writes when Rate Limit counts in a shared KV store. */
76
+ rateLimit: string;
77
+ }
78
+ /** Options of `comments()`, for apps that use Comments without `vite-hub`. */
79
+ interface CommentsOptions {
80
+ /**
81
+ * Where threads are stored. Comments creates its tables there on first use, so there is no migration.
82
+ *
83
+ * - Not set: `DATABASE_URL`, else `TURSO_DATABASE_URL`, else the Cloudflare D1 binding `DB`, read at runtime.
84
+ * - `"d1:COMMENTS"`: the Cloudflare D1 binding `COMMENTS`. Comments adds it to the Wrangler config.
85
+ * - `"env:COMMENTS_DATABASE_URL"`: the libSQL URL in that variable, with its token in `COMMENTS_AUTH_TOKEN`.
86
+ * - `"file:./data/comments.sqlite"`: a SQLite file on Node, relative to the server's working directory.
87
+ *
88
+ * The development server uses `.vitehub/data/comments.sqlite`, unless `database` is a file or a set variable. Under a
89
+ * Nitro Cloudflare preset, it runs in workerd, which cannot open that file, so it uses a local D1 binding `COMMENTS`
90
+ * instead, unless `database` names another location. An unset `env:` variable falls back to that local D1 database.
91
+ */
92
+ database?: string;
93
+ }
94
+ /** The storage of a `comments()` build: where to connect, the file to use without a connection, and whether it needs Node. */
95
+ interface StandaloneDatabase {
96
+ where?: string;
97
+ fallback?: string;
98
+ node: boolean;
99
+ }
100
+ interface CommentsVitePluginOptions {
101
+ /**
102
+ * `true` turns Comments on without `server/comments.ts`, with the default `defineComments()`. `vitehub({ comments })`
103
+ * sets it. Default: Comments is on when the app has the file.
104
+ */
105
+ enabled?: boolean;
106
+ /** Whether the app configures ViteHub Auth, so Comments reads its session. Default `false`. */
107
+ auth?: boolean;
108
+ imports?: Partial<CommentsImports>;
109
+ /**
110
+ * Comments without `vite-hub`, as `comments()` sets it: it turns on without `server/comments.ts`, keeps threads in a
111
+ * SQLite file that it opens itself, and signs people in with GitHub.
112
+ */
113
+ standalone?: CommentsOptions;
114
+ /** The Database Definition that receives the tables. Default: `defineComments({ database })`, else the default or only Database. */
115
+ database?: string;
116
+ /** SQL dialect of that Database. `postgresql` uses the Postgres tables. Default `sqlite`: SQLite, libSQL, and D1. */
117
+ dialect?: "postgresql" | "sqlite";
118
+ /** Store attachments in the app's Blob store. Default `false`: uploads need `defineComments({ storeAttachment })`. */
119
+ blob?: boolean;
120
+ /**
121
+ * `false` leaves the overlay out: no `comments` page tool. The API, the operations, and the Console stay.
122
+ * `{ presence: false }` keeps the overlay without its faces and cursors, for an app that shows its own presence.
123
+ */
124
+ overlay?: false | {
125
+ presence?: false;
126
+ };
127
+ /**
128
+ * ViteHub Rate Limit counts in a KV store that every server process shares: count the guest writes of
129
+ * `defineComments({ rateLimit })` there too. Default `false`: each process counts in its memory.
130
+ */
131
+ rateLimit?: boolean;
132
+ }
133
+ interface CommentsRealtimeContributionContext {
134
+ driver: "cloudflare" | "memory";
135
+ directory: string;
136
+ projectRoot: string;
137
+ serverDirs?: string[];
138
+ }
139
+ /** The names and source files resolved by Nuxt's component scanner. */
140
+ interface CommentsComponent {
141
+ pascalName: string;
142
+ filePath: string;
143
+ }
144
+ type CommentsVitePlugin$1 = Plugin & {
145
+ nitro?: NitroModule;
146
+ api: {
147
+ /** The variables that Comments reads on the deployed host. See `commentsDeploymentEnv()`. */
148
+ deploymentEnv: DeploymentEnvContribution;
149
+ /** Supplies Nuxt's effective component names, and refreshes the generated map after a rescan. */
150
+ setComponents(components: readonly CommentsComponent[]): Promise<void>;
151
+ /**
152
+ * The `comments` Realtime Definition of the page presence rooms, for `hubRealtime({ contribute })`. Realtime calls
153
+ * it only when the host has a room authority; without one, pages show comments without presence.
154
+ */
155
+ contributeRealtime(context: CommentsRealtimeContributionContext): Promise<{
156
+ definitions: Array<{
157
+ handler: string;
158
+ name: string;
159
+ }>;
160
+ } | undefined>;
161
+ };
162
+ vitehub: ViteHubInspectionPluginMetadata & {
163
+ databases: (context: DatabaseContributionContext) => Promise<DatabaseContributionEntry[]>;
164
+ };
165
+ };
166
+ /**
167
+ * The Database name in `defineComments({ database: "name" })`, read without running the file. Undefined means the
168
+ * default or only Database.
169
+ */
170
+ export declare function readCommentsDatabase(file: string): Promise<string | undefined>;
171
+ /** The directory of the prebuilt overlay script in this package. */
172
+ export declare function commentsOverlayDirectory(): string;
173
+ /**
174
+ * The build of the app, from the CI or host, else from Git: the commit and branch, the GitHub repository, and the pull
175
+ * request when the host names it. Empty outside a Git checkout. Forge's `readForgeBuild` reads it.
176
+ */
177
+ export declare function readCommentsBuild(root: string, env?: Record<string, string | undefined>): Promise<CommentBuild>;
178
+ /**
179
+ * The names that a production build may give the component of a `.vue` file: its file name, which `<script setup>`
180
+ * uses; under `pages/`, the Nuxt route name, such as `blog-id` for `pages/blog/[id].vue`.
181
+ * Nuxt component names come from its resolved registry rather than a path heuristic.
182
+ */
183
+ export declare function componentNames(file: string): string[];
184
+ /**
185
+ * The Vue files of a project by component name, relative to the project root. `<script setup>` components carry the
186
+ * name of their file in production builds, so the name finds the file. It skips dot directories and build output.
187
+ */
188
+ export declare function readCommentsComponents(root: string, limit?: number, resolvedComponents?: readonly CommentsComponent[]): Promise<Record<string, string[]>>;
189
+ export declare function renderCommentsHandler(input: {
190
+ definition: string;
191
+ content?: string;
192
+ session: CommentsVitePluginOptions;
193
+ realtime: boolean;
194
+ imports: CommentsImports;
195
+ build?: CommentBuild;
196
+ base?: string;
197
+ }): string;
198
+ export declare function renderCommentsPlugin(input: {
199
+ definition: string;
200
+ database?: string;
201
+ session?: CommentsVitePluginOptions;
202
+ imports: CommentsImports;
203
+ standalone?: StandaloneDatabase;
204
+ development?: boolean;
205
+ build?: CommentBuild;
206
+ base?: string;
207
+ }): string;
208
+ /**
209
+ * Comments for any Vite app, without `vite-hub`: the comment overlay on every page with `?vitehub`, threads in a
210
+ * SQLite file, and Sign in with GitHub. It adds Nitro, the server, unless the app has it. Next to `vitehub()` it fails
211
+ * with `COMMENTS_B0003`, because `vitehub({ comments })` and `server/comments.ts` turn Comments on there.
212
+ */
213
+ export declare function comments(options?: CommentsOptions): PluginOption[];
214
+ //#endregion
215
+ //#region src/overlay.d.ts
216
+ /** Which pages get the overlay. Globs are relative to the app base: `*` is one path segment and `**` any depth. */
217
+ interface CommentsOverlayOptions {
218
+ /** Pages that get the overlay. Default: every page. */
219
+ paths?: string[];
220
+ /** Pages that never get it. */
221
+ exclude?: string[];
222
+ /**
223
+ * When the loader asks the server whether the visitor may read comments. Default `"always"`: on page load and
224
+ * navigation. `"marker"` also requires a readable `vitehub_session` cookie maintained by your app's auth lifecycle.
225
+ */
226
+ session?: "always" | "marker";
227
+ }
228
+ /**
229
+ * The prebuilt loader and overlay. `vite-hub` supplies them. Both file names carry a hash of their content, so a page
230
+ * names the exact versions it loads and an old page can never mix with a new bundle.
231
+ */
232
+ interface CommentsOverlayAssets {
233
+ /** Directory with the two files. */
234
+ dir: string;
235
+ /** File name of the loader, such as `loader.1a2b3c4d.js`. */
236
+ loader: string;
237
+ /** File name of the overlay, such as `overlay.5e6f7a8b.js`. */
238
+ overlay: string;
239
+ }
240
+ /** Where the loader and overlay are served, below the app mount. */
241
+ export declare const overlayRoute = "/_vitehub/comments";
242
+ /** The path the app is mounted at: `""` for the root, `"/portal"` below it. A relative or empty Vite base is the root. */
243
+ export declare function mountPath(base: string | undefined): string;
244
+ /** The URL of the loader. Its query names the overlay file, says whether the app can edit pages, and carries the page filter and when to ask. */
245
+ export declare function loaderUrl(mount: string, assets: Pick<CommentsOverlayAssets, "loader" | "overlay">, options?: CommentsOverlayOptions & {
246
+ edit?: boolean;
247
+ }): string;
248
+ export declare function loaderTag(url: string, nonce?: string): string;
249
+ /** The nonce that a `Content-Security-Policy` allows for scripts, when it has one. */
250
+ export declare function scriptNonce(policy: string | null | undefined): string | undefined;
251
+ /** Puts the tag before the first `</body>` or `</html>`. A fragment, or a page that has the loader, stays as it is. */
252
+ export declare function injectLoader(html: string, tag: string, found?: {
253
+ scanned: number;
254
+ close?: number;
255
+ loaded?: {
256
+ start: number;
257
+ end: number;
258
+ };
259
+ }): string;
260
+ /**
261
+ * Source of the Nitro middleware that adds the loader to HTML responses: server-rendered pages and, when Nitro
262
+ * prerenders them, the saved files. It is Nitro middleware `(event, next)`.
263
+ *
264
+ * It rewrites only what is safe to rewrite: UTF-8 `text/html` that is not compressed, with a `</body>` or `</html>`.
265
+ * A stream is piped through a transform that holds back a short tail, so a tag split across chunks is still found.
266
+ */
267
+ export declare function renderOverlayMiddleware(url: string): string;
268
+ //#endregion
269
+ //#region src/operations-core/console.d.ts
270
+ /**
271
+ * Console section for the comment inbox. It lists the result of `comments.list`, called with the Console user, so
272
+ * `authorize` applies to each thread. A page thread links to `<page>?comment=<n>`.
273
+ */
274
+ declare const commentsConsoleSection$1: ViteHubConsoleOperationSection;
275
+ //#endregion
276
+ //#region src/operations-core/vite.d.ts
277
+ export declare const COMMENTS_VITE_PLUGIN_NAME = "@vite-hub/comments/vite";
278
+ /** Whether the project has a `server/comments.ts`. `vitehub()` reads it while Vite filters plugins. */
279
+ export declare function usesComments(options: {
280
+ projectRoot: string;
281
+ serverDirs?: readonly string[];
282
+ }): boolean;
283
+ //#endregion
284
+ //#region src/vite.d.ts
285
+ export type HubCommentsOptions = CommentsVitePluginOptions & {
286
+ /** Import paths of the comment operations. `vite-hub` passes its own subpaths. */
287
+ operationsImports?: {
288
+ operations?: string;
289
+ };
290
+ };
291
+ export type CommentsVitePlugin = CommentsVitePlugin$1 & {
292
+ vitehub: CommentsVitePlugin$1["vitehub"] & {
293
+ operations: OperationContributions;
294
+ };
295
+ };
296
+ export declare function findCommentsEntry(projectRoot: string, serverDirs?: readonly string[]): string | undefined;
297
+ export declare function findCommentsEntry(options: {
298
+ projectRoot: string;
299
+ serverDirs?: readonly string[];
300
+ }): string | undefined;
301
+ /**
302
+ * Comments in a ViteHub app, from one `server/comments.ts`: the Comments API and the overlay, presence rooms, the MCP
303
+ * tools, and the comment operations of the Console, the CLI, and MCP. The file may export the definition as `comments`
304
+ * or as its default export; both run every surface on the same tables.
305
+ */
306
+ export declare function hubComments(options?: HubCommentsOptions): CommentsVitePlugin;
307
+ //#endregion
308
+ export { type CommentsComponent, type CommentsImports, type CommentsOptions, type CommentsOverlayAssets, type CommentsOverlayOptions, type CommentsRealtimeContributionContext, type CommentsVitePluginOptions, type StandaloneDatabase, comments as default, commentsConsoleSection$1 as commentsOperationsConsoleSection, githubRepository, mountedCommentsRoute };