@vite-hub/comments 0.0.0-stage → 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 +242 -2
  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 -3
package/dist/vite.d.ts ADDED
@@ -0,0 +1,304 @@
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";
5
+ import { Plugin, PluginOption } from "vite";
6
+ import { DatabaseContributionContext, DatabaseContributionEntry } from "@vite-hub/database/vite";
7
+ import { NitroModule } from "nitro/types";
8
+ //#region src/console.d.ts
9
+ /**
10
+ * 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
12
+ * Console shows it when the app has `server/comments.ts`.
13
+ */
14
+ export declare const commentsConsoleSection: ViteHubConsoleRuntimeRecordTableSection<{
15
+ projectRoot: string;
16
+ serverDirs?: string[];
17
+ }>;
18
+ //#endregion
19
+ //#region src/live-vite.d.ts
20
+ /** Module paths that generated files import. The `vite-hub` distribution passes its own subpaths. */
21
+ interface CommentsImports {
22
+ /** Exports `defineCommentsPlugin`, `createCommentsHandler`, and `viteHubPageSessionHandler`. */
23
+ runtime: string;
24
+ /** Exports `commentsRealtime`. */
25
+ realtime: string;
26
+ /** Exports `commentsAuthSession`. */
27
+ auth: string;
28
+ /** Exports `commentsSchema`. */
29
+ database: string;
30
+ /** Exports `databases`, the runtime Database registry. */
31
+ databases: string;
32
+ /** Exports `parseContentField`. */
33
+ contentClient: string;
34
+ /** Exports `connectDatabase`, for Workers. Its `/node` subpath also opens SQLite files. */
35
+ connect: string;
36
+ }
37
+ /** Options of `comments()`, for apps that use Comments without `vite-hub`. */
38
+ interface CommentsOptions {
39
+ /**
40
+ * Where threads are stored. Comments creates its tables there on first use, so there is no migration.
41
+ *
42
+ * - Not set: `DATABASE_URL`, else `TURSO_DATABASE_URL`, else the Cloudflare D1 binding `DB`, read at runtime.
43
+ * - `"d1:COMMENTS"`: the Cloudflare D1 binding `COMMENTS`. Comments adds it to the Wrangler config.
44
+ * - `"env:COMMENTS_DATABASE_URL"`: the libSQL URL in that variable, with its token in `COMMENTS_AUTH_TOKEN`.
45
+ * - `"file:./data/comments.sqlite"`: a SQLite file on Node, relative to the server's working directory.
46
+ *
47
+ * The development server uses `.vitehub/data/comments.sqlite`, unless `database` is a file or a set variable. Under a
48
+ * Nitro Cloudflare preset, it runs in workerd, which cannot open that file, so it uses a local D1 binding `COMMENTS`
49
+ * instead, unless `database` names another location. An unset `env:` variable falls back to that local D1 database.
50
+ */
51
+ database?: string;
52
+ }
53
+ /** The storage of a `comments()` build: where to connect, the file to use without a connection, and whether it needs Node. */
54
+ interface StandaloneDatabase {
55
+ where?: string;
56
+ fallback?: string;
57
+ node: boolean;
58
+ }
59
+ interface CommentsVitePluginOptions {
60
+ /** Whether the app configures ViteHub Auth, so Comments reads its session. Default `false`. */
61
+ auth?: boolean;
62
+ /**
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.
65
+ */
66
+ console?: {
67
+ module: string;
68
+ };
69
+ imports?: Partial<CommentsImports>;
70
+ /**
71
+ * Comments without `vite-hub`, as `comments()` sets it: it turns on without `server/comments.ts`, keeps threads in a
72
+ * SQLite file that it opens itself, and signs people in with GitHub.
73
+ */
74
+ standalone?: CommentsOptions;
75
+ }
76
+ interface CommentsRealtimeContributionContext {
77
+ authority: "cloudflare" | "memory";
78
+ directory: string;
79
+ projectRoot: string;
80
+ serverDirs?: string[];
81
+ }
82
+ /** The names and source files resolved by Nuxt's component scanner. */
83
+ interface CommentsComponent {
84
+ pascalName: string;
85
+ filePath: string;
86
+ }
87
+ type CommentsVitePlugin$2 = Plugin & {
88
+ nitro?: NitroModule;
89
+ api: {
90
+ /** Supplies Nuxt's effective component names, and refreshes the generated map after a rescan. */
91
+ setComponents(components: readonly CommentsComponent[]): Promise<void>;
92
+ /**
93
+ * The `comments` Realtime Definition of the page presence rooms, for `hubRealtime({ contribute })`. Realtime calls
94
+ * it only when the host has a room authority; without one, pages show comments without presence.
95
+ */
96
+ contributeRealtime(context: CommentsRealtimeContributionContext): Promise<{
97
+ definitions: Array<{
98
+ handler: string;
99
+ name: string;
100
+ }>;
101
+ } | undefined>;
102
+ };
103
+ vitehub: ViteHubInspectionPluginMetadata & {
104
+ databases: (context: DatabaseContributionContext) => Promise<DatabaseContributionEntry[]>;
105
+ };
106
+ };
107
+ /**
108
+ * The Database name in `defineComments({ database: "name" })`, read without running the file. Undefined means the
109
+ * default or only Database.
110
+ */
111
+ export declare function readCommentsDatabase(file: string): Promise<string | undefined>;
112
+ /** The directory of the prebuilt overlay script in this package. */
113
+ 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
+ /**
117
+ * 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.
119
+ */
120
+ export declare function readCommentsBuild(root: string, env?: Record<string, string | undefined>): Promise<CommentBuild>;
121
+ /**
122
+ * The names that a production build may give the component of a `.vue` file: its file name, which `<script setup>`
123
+ * uses; under `pages/`, the Nuxt route name, such as `blog-id` for `pages/blog/[id].vue`.
124
+ * Nuxt component names come from its resolved registry rather than a path heuristic.
125
+ */
126
+ export declare function componentNames(file: string): string[];
127
+ /**
128
+ * The Vue files of a project by component name, relative to the project root. `<script setup>` components carry the
129
+ * name of their file in production builds, so the name finds the file. It skips dot directories and build output.
130
+ */
131
+ export declare function readCommentsComponents(root: string, limit?: number, resolvedComponents?: readonly CommentsComponent[]): Promise<Record<string, string[]>>;
132
+ export declare function renderCommentsHandler(input: {
133
+ definition: string;
134
+ content?: string;
135
+ session: CommentsVitePluginOptions;
136
+ realtime: boolean;
137
+ imports: CommentsImports;
138
+ build?: CommentBuild;
139
+ base?: string;
140
+ }): string;
141
+ export declare function renderCommentsPlugin(input: {
142
+ definition: string;
143
+ database?: string;
144
+ session?: CommentsVitePluginOptions;
145
+ imports: CommentsImports;
146
+ standalone?: StandaloneDatabase;
147
+ development?: boolean;
148
+ build?: CommentBuild;
149
+ base?: string;
150
+ }): string;
151
+ /**
152
+ * 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.
155
+ */
156
+ export declare function comments(options?: CommentsOptions): PluginOption[];
157
+ //#endregion
158
+ //#region src/overlay.d.ts
159
+ /** Which pages get the overlay. Globs are relative to the app base: `*` is one path segment and `**` any depth. */
160
+ interface CommentsOverlayOptions {
161
+ /** Pages that get the overlay. Default: every page. */
162
+ paths?: string[];
163
+ /** Pages that never get it. */
164
+ exclude?: string[];
165
+ /**
166
+ * When the loader asks the server whether the visitor may read comments. Default `"always"`: on page load and
167
+ * navigation. `"marker"` also requires a readable `vitehub_session` cookie maintained by your app's auth lifecycle.
168
+ */
169
+ session?: "always" | "marker";
170
+ }
171
+ /**
172
+ * The prebuilt loader and overlay. `vite-hub` supplies them. Both file names carry a hash of their content, so a page
173
+ * names the exact versions it loads and an old page can never mix with a new bundle.
174
+ */
175
+ interface CommentsOverlayAssets {
176
+ /** Directory with the two files. */
177
+ dir: string;
178
+ /** File name of the loader, such as `loader.1a2b3c4d.js`. */
179
+ loader: string;
180
+ /** File name of the overlay, such as `overlay.5e6f7a8b.js`. */
181
+ overlay: string;
182
+ }
183
+ /** Where the loader and overlay are served, below the app mount. */
184
+ export declare const overlayRoute = "/_vitehub/comments";
185
+ /** The path the app is mounted at: `""` for the root, `"/portal"` below it. A relative or empty Vite base is the root. */
186
+ export declare function mountPath(base: string | undefined): string;
187
+ /** 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. */
188
+ export declare function loaderUrl(mount: string, assets: Pick<CommentsOverlayAssets, "loader" | "overlay">, options?: CommentsOverlayOptions & {
189
+ edit?: boolean;
190
+ }): string;
191
+ export declare function loaderTag(url: string, nonce?: string): string;
192
+ /** The nonce that a `Content-Security-Policy` allows for scripts, when it has one. */
193
+ export declare function scriptNonce(policy: string | null | undefined): string | undefined;
194
+ /** Puts the tag before the first `</body>` or `</html>`. A fragment, or a page that has the loader, stays as it is. */
195
+ export declare function injectLoader(html: string, tag: string, found?: {
196
+ scanned: number;
197
+ close?: number;
198
+ loaded?: {
199
+ start: number;
200
+ end: number;
201
+ };
202
+ }): string;
203
+ /**
204
+ * 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.
207
+ *
208
+ * It rewrites only what is safe to rewrite: UTF-8 `text/html` that is not compressed, with a `</body>` or `</html>`.
209
+ * A stream is piped through a transform that holds back a short tail, so a tag split across chunks is still found.
210
+ */
211
+ export declare function renderOverlayMiddleware(url: string): string;
212
+ //#endregion
213
+ //#region src/operations-core/console.d.ts
214
+ /**
215
+ * Console section for the comment inbox. It lists the result of `comments.list`, called with the Console user, so
216
+ * `authorize` applies to each thread. A page thread links to `<page>?comment=<n>`.
217
+ */
218
+ declare const commentsConsoleSection$1: ViteHubConsoleOperationSection;
219
+ //#endregion
220
+ //#region src/operations-core/vite.d.ts
221
+ 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
+ /** Whether the project has a `server/comments.ts`. `vitehub()` reads it while Vite filters plugins. */
274
+ export declare function usesComments(options: {
275
+ projectRoot: string;
276
+ serverDirs?: readonly string[];
277
+ }): 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
+ //#endregion
287
+ //#region src/vite.d.ts
288
+ export type HubCommentsOptions = Omit<HubCommentsOptions$1, "imports"> & CommentsVitePluginOptions & {
289
+ operationsImports?: HubCommentsOptions$1["imports"];
290
+ };
291
+ export type CommentsVitePlugin = CommentsVitePlugin$1 & {
292
+ api: CommentsVitePlugin$2["api"];
293
+ };
294
+ export declare function findCommentsEntry(projectRoot: string, serverDirs?: readonly string[]): string | undefined;
295
+ export declare function findCommentsEntry(options: {
296
+ projectRoot: string;
297
+ serverDirs?: readonly string[];
298
+ }): 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. */
302
+ export declare function hubComments(options?: HubCommentsOptions): CommentsVitePlugin;
303
+ //#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 };