@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.
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/dist/vite.d.ts CHANGED
@@ -1,14 +1,16 @@
1
- import { i as CommentBuild } from "./types-Un2dcJWD.js";
2
- import { a as mountedCommentsRoute } from "./page-BtXADR6d.js";
3
- import { n as OperationContributions } from "./operations-0B0QTVWX.js";
4
- import { i as ViteHubInspectionPluginMetadata, r as ViteHubConsoleRuntimeRecordTableSection, t as ViteHubConsoleOperationSection } from "./console-BIz9t2cO.js";
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";
5
6
  import { Plugin, PluginOption } from "vite";
7
+ import { githubRepository } from "@vite-hub/forge/build/node";
6
8
  import { DatabaseContributionContext, DatabaseContributionEntry } from "@vite-hub/database/vite";
7
9
  import { NitroModule } from "nitro/types";
8
10
  //#region src/console.d.ts
9
11
  /**
10
12
  * Console section for Comments: every thread with its first comment, page, author, replies, and status, open threads
11
- * first. People reply and resolve on the page itself, where the context is; each record links there with the page tools on. The
13
+ * first. People reply and resolve on the page itself, where the context is; each record links there. The
12
14
  * Console shows it when the app has `server/comments.ts`.
13
15
  */
14
16
  export declare const commentsConsoleSection: ViteHubConsoleRuntimeRecordTableSection<{
@@ -16,6 +18,41 @@ export declare const commentsConsoleSection: ViteHubConsoleRuntimeRecordTableSec
16
18
  serverDirs?: string[];
17
19
  }>;
18
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
19
56
  //#region src/live-vite.d.ts
20
57
  /** Module paths that generated files import. The `vite-hub` distribution passes its own subpaths. */
21
58
  interface CommentsImports {
@@ -33,6 +70,10 @@ interface CommentsImports {
33
70
  contentClient: string;
34
71
  /** Exports `connectDatabase`, for Workers. Its `/node` subpath also opens SQLite files. */
35
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;
36
77
  }
37
78
  /** Options of `comments()`, for apps that use Comments without `vite-hub`. */
38
79
  interface CommentsOptions {
@@ -57,24 +98,40 @@ interface StandaloneDatabase {
57
98
  node: boolean;
58
99
  }
59
100
  interface CommentsVitePluginOptions {
60
- /** Whether the app configures ViteHub Auth, so Comments reads its session. Default `false`. */
61
- auth?: boolean;
62
101
  /**
63
- * The Console of the app: a module and its `consoleRealtimeAccess` export. With it, the people that the Console lets
64
- * use its `comments` section are the people of Comments, and opening the Console turns the page tools on for them.
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.
65
104
  */
66
- console?: {
67
- module: string;
68
- };
105
+ enabled?: boolean;
106
+ /** Whether the app configures ViteHub Auth, so Comments reads its session. Default `false`. */
107
+ auth?: boolean;
69
108
  imports?: Partial<CommentsImports>;
70
109
  /**
71
110
  * Comments without `vite-hub`, as `comments()` sets it: it turns on without `server/comments.ts`, keeps threads in a
72
111
  * SQLite file that it opens itself, and signs people in with GitHub.
73
112
  */
74
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;
75
132
  }
76
133
  interface CommentsRealtimeContributionContext {
77
- authority: "cloudflare" | "memory";
134
+ driver: "cloudflare" | "memory";
78
135
  directory: string;
79
136
  projectRoot: string;
80
137
  serverDirs?: string[];
@@ -84,9 +141,11 @@ interface CommentsComponent {
84
141
  pascalName: string;
85
142
  filePath: string;
86
143
  }
87
- type CommentsVitePlugin$2 = Plugin & {
144
+ type CommentsVitePlugin$1 = Plugin & {
88
145
  nitro?: NitroModule;
89
146
  api: {
147
+ /** The variables that Comments reads on the deployed host. See `commentsDeploymentEnv()`. */
148
+ deploymentEnv: DeploymentEnvContribution;
90
149
  /** Supplies Nuxt's effective component names, and refreshes the generated map after a rescan. */
91
150
  setComponents(components: readonly CommentsComponent[]): Promise<void>;
92
151
  /**
@@ -111,11 +170,9 @@ type CommentsVitePlugin$2 = Plugin & {
111
170
  export declare function readCommentsDatabase(file: string): Promise<string | undefined>;
112
171
  /** The directory of the prebuilt overlay script in this package. */
113
172
  export declare function commentsOverlayDirectory(): string;
114
- /** `owner/name` of a GitHub or Enterprise remote. The forge's API URL selects the server at runtime. */
115
- export declare function githubRepository(remote: string | undefined): string | undefined;
116
173
  /**
117
174
  * The build of the app, from the CI or host, else from Git: the commit and branch, the GitHub repository, and the pull
118
- * request when the host names it. Empty outside a Git checkout.
175
+ * request when the host names it. Empty outside a Git checkout. Forge's `readForgeBuild` reads it.
119
176
  */
120
177
  export declare function readCommentsBuild(root: string, env?: Record<string, string | undefined>): Promise<CommentBuild>;
121
178
  /**
@@ -150,8 +207,8 @@ export declare function renderCommentsPlugin(input: {
150
207
  }): string;
151
208
  /**
152
209
  * Comments for any Vite app, without `vite-hub`: the comment overlay on every page with `?vitehub`, threads in a
153
- * SQLite file, and Sign in with GitHub. It adds Nitro, the server, unless the app has it. With `vite-hub`, it does
154
- * nothing, because `vitehub()` runs Comments.
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.
155
212
  */
156
213
  export declare function comments(options?: CommentsOptions): PluginOption[];
157
214
  //#endregion
@@ -202,8 +259,7 @@ export declare function injectLoader(html: string, tag: string, found?: {
202
259
  }): string;
203
260
  /**
204
261
  * Source of the Nitro middleware that adds the loader to HTML responses: server-rendered pages and, when Nitro
205
- * prerenders them, the saved files. It is Nitro 3 middleware `(event, next)`. Where the host calls it without `next`,
206
- * such as Nitro 2 under Nuxt, it does nothing, and the `render:html` hook of the runtime plugin does the work.
262
+ * prerenders them, the saved files. It is Nitro middleware `(event, next)`.
207
263
  *
208
264
  * It rewrites only what is safe to rewrite: UTF-8 `text/html` that is not compressed, with a `</body>` or `</html>`.
209
265
  * A stream is piped through a transform that holds back a short tail, so a tag split across chunks is still found.
@@ -219,86 +275,34 @@ declare const commentsConsoleSection$1: ViteHubConsoleOperationSection;
219
275
  //#endregion
220
276
  //#region src/operations-core/vite.d.ts
221
277
  export declare const COMMENTS_VITE_PLUGIN_NAME = "@vite-hub/comments/vite";
222
- /** Generated Nitro plugin that installs the comments runtime, relative to the project root. */
223
- export declare const commentsNitroPluginPath = ".vitehub/nitro/comments/plugin.mjs";
224
- /** Generated Nitro middleware that adds the overlay loader to HTML responses, relative to the project root. */
225
- export declare const commentsOverlayMiddlewarePath = ".vitehub/comments/inject-overlay.mjs";
226
- /** Generated Database Definition that comments add when the app has none, relative to the project root. */
227
- export declare const commentsDatabaseModulePath = ".vitehub/comments/database.ts";
228
- /** The `default` Database that comments add when the app has no Database Definition. */
229
- export declare function renderCommentsDatabaseModule(imports: Pick<CommentsImports$1, "databaseDefinition">, dialect?: "postgresql" | "sqlite"): string;
230
- /** Import paths of the generated runtime. The `vite-hub` integration passes its own subpaths, so the module resolves from the app. */
231
- interface CommentsImports$1 {
232
- auth: string;
233
- database: string;
234
- /** Module of `defineDatabase()`, for the `default` Database that comments add when the app has none. */
235
- databaseDefinition: string;
236
- databaseSchema: string;
237
- operations: string;
238
- runtime: string;
239
- }
240
- interface HubCommentsOptions$1 {
241
- /** Database Definition that receives the tables. Defaults to the default or only Database. */
242
- database?: string;
243
- /** SQL dialect of that Database. `postgresql` uses the Postgres tables. Default `sqlite`: SQLite, libSQL, and D1. */
244
- dialect?: "postgresql" | "sqlite";
245
- /** Find people through the app Auth for @mentions. Default `false`: the authors that comments know. */
246
- auth?: boolean;
247
- /**
248
- * The overlay on the pages of the app: a loader that downloads the comment UI only for visitors who may read comments.
249
- * `false` turns it off. `paths` and `exclude` are globs relative to the app base. Default: every page.
250
- */
251
- overlay?: false | CommentsOverlayOptions;
252
- /** The prebuilt loader and overlay. `vite-hub` supplies them. Without them there is no overlay. */
253
- overlayAssets?: CommentsOverlayAssets;
254
- /** The host provides the operation RPC only during development. */
255
- overlayDevOnly?: boolean;
256
- /**
257
- * Whether the app can edit the page behind a URL, which shows the overlay's Edit button. `vite-hub` passes a check
258
- * for the Content cms preset. Without it the overlay never asks `content.resolve`, which an app with no Content does
259
- * not have.
260
- */
261
- overlayEdit?: (project: {
262
- projectRoot: string;
263
- serverDirs?: readonly string[];
264
- }) => boolean;
265
- imports?: Partial<CommentsImports$1>;
266
- }
267
- type CommentsVitePlugin$1 = Plugin & {
268
- vitehub: {
269
- databases: (context: DatabaseContributionContext) => Promise<readonly DatabaseContributionEntry[]>;
270
- operations: OperationContributions;
271
- } & ViteHubInspectionPluginMetadata;
272
- };
273
278
  /** Whether the project has a `server/comments.ts`. `vitehub()` reads it while Vite filters plugins. */
274
279
  export declare function usesComments(options: {
275
280
  projectRoot: string;
276
281
  serverDirs?: readonly string[];
277
282
  }): boolean;
278
- /** The Nitro plugin that installs the comments runtime in each server process. */
279
- export declare function renderCommentsNitroPlugin(options: {
280
- auth: boolean;
281
- database?: string;
282
- entry: string;
283
- imports: CommentsImports$1;
284
- overlayUrl?: string;
285
- }): string;
286
283
  //#endregion
287
284
  //#region src/vite.d.ts
288
- export type HubCommentsOptions = Omit<HubCommentsOptions$1, "imports"> & CommentsVitePluginOptions & {
289
- operationsImports?: HubCommentsOptions$1["imports"];
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
290
  };
291
291
  export type CommentsVitePlugin = CommentsVitePlugin$1 & {
292
- api: CommentsVitePlugin$2["api"];
292
+ vitehub: CommentsVitePlugin$1["vitehub"] & {
293
+ operations: OperationContributions;
294
+ };
293
295
  };
294
296
  export declare function findCommentsEntry(projectRoot: string, serverDirs?: readonly string[]): string | undefined;
295
297
  export declare function findCommentsEntry(options: {
296
298
  projectRoot: string;
297
299
  serverDirs?: readonly string[];
298
300
  }): string | undefined;
299
- /** A default export opts into Operations; the named `comments` export retains the live-site API. */
300
- export declare function commentsEntryMode(file: string): "operations" | "live";
301
- /** Select one runtime and schema so the two entry forms never install competing thread tables. */
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
+ */
302
306
  export declare function hubComments(options?: HubCommentsOptions): CommentsVitePlugin;
303
307
  //#endregion
304
- export { type CommentsComponent, type CommentsImports, type CommentsOptions, type CommentsOverlayAssets, type CommentsOverlayOptions, type CommentsRealtimeContributionContext, type CommentsVitePluginOptions, type StandaloneDatabase, comments as default, commentsConsoleSection$1 as commentsOperationsConsoleSection, mountedCommentsRoute };
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 };