@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,21 @@
1
+ //#region src/page.d.ts
2
+ /** Name of the Realtime Definition that holds one presence room per page. */
3
+ /**
4
+ * The scope of the threads that people pin on the app's pages with the overlay. Threads that app code starts in its
5
+ * own UI use their own scope, such as `doc:42`.
6
+ */
7
+ declare const commentsPageScope = "pages";
8
+ declare const commentsRealtimeDefinition = "comments";
9
+ /** The route prefix of the Comments API, below the app base. */
10
+ declare const commentsRoute = "/api/_vitehub/comments";
11
+ /** Mount Comments under the application path, ignoring Vite asset URLs such as a CDN origin. */
12
+ declare function mountedCommentsRoute(base?: string): string;
13
+ /**
14
+ * The key of a page: its pathname without query or hash, and without a trailing slash except for `/`. Threads and
15
+ * presence rooms belong to a page key.
16
+ */
17
+ declare function normalizeCommentPage(path: string): string;
18
+ /** The Realtime document id of the presence room of a page: `pages/<hash>`, a safe Workspace path for any page. */
19
+ declare function commentRoom(page: string): string;
20
+ //#endregion
21
+ export { mountedCommentsRoute as a, commentsRoute as i, commentsPageScope as n, normalizeCommentPage as o, commentsRealtimeDefinition as r, commentRoom as t };
@@ -0,0 +1,38 @@
1
+ //#region src/page.ts
2
+ /** Name of the Realtime Definition that holds one presence room per page. */
3
+ /**
4
+ * The scope of the threads that people pin on the app's pages with the overlay. Threads that app code starts in its
5
+ * own UI use their own scope, such as `doc:42`.
6
+ */
7
+ const commentsPageScope = "pages";
8
+ const commentsRealtimeDefinition = "comments";
9
+ /** The route prefix of the Comments API, below the app base. */
10
+ const commentsRoute = "/api/_vitehub/comments";
11
+ /** Mount Comments under the application path, ignoring Vite asset URLs such as a CDN origin. */
12
+ function mountedCommentsRoute(base = "/") {
13
+ return base.startsWith("/") && !base.startsWith("//") ? `${base.replace(/\/+$/, "")}${commentsRoute}` : commentsRoute;
14
+ }
15
+ /**
16
+ * The key of a page: its pathname without query or hash, and without a trailing slash except for `/`. Threads and
17
+ * presence rooms belong to a page key.
18
+ */
19
+ function normalizeCommentPage(path) {
20
+ let pathname = path.split(/[?#]/, 1)[0] ?? "";
21
+ if (!pathname.startsWith("/")) pathname = `/${pathname}`;
22
+ pathname = pathname.replace(/\/{2,}/g, "/");
23
+ if (pathname.length > 1) pathname = pathname.replace(/\/+$/, "");
24
+ return pathname || "/";
25
+ }
26
+ /** The Realtime document id of the presence room of a page: `pages/<hash>`, a safe Workspace path for any page. */
27
+ function commentRoom(page) {
28
+ let a = 2166136261;
29
+ let b = 1523705862;
30
+ for (let index = 0; index < page.length; index++) {
31
+ const code = page.charCodeAt(index);
32
+ a = Math.imul(a ^ code, 16777619) >>> 0;
33
+ b = Math.imul(b ^ code, 2671213388) >>> 0;
34
+ }
35
+ return `pages/${a.toString(16).padStart(8, "0")}${b.toString(16).padStart(8, "0")}`;
36
+ }
37
+ //#endregion
38
+ export { mountedCommentsRoute as a, commentsRoute as i, commentsPageScope as n, normalizeCommentPage as o, commentsRealtimeDefinition as r, commentRoom as t };
@@ -0,0 +1,53 @@
1
+ //#region ../internal/src/runtime/page-tools-shared.ts
2
+ /**
3
+ * The names and the session answer that the page tools server and the browser loader share. It has no DOM and no Node
4
+ * code, so both sides import it.
5
+ */
6
+ /** The query that turns the page tools on for a page. `?vitehub=<tool id>` also opens that tool. */
7
+ const viteHubPageToolsQuery = "vitehub";
8
+ /** The cookie that keeps the page tools on, on the next pages. It is a hint, never a credential. */
9
+ const viteHubPageToolsCookie = "vitehub-tools";
10
+ /**
11
+ * The URL prefix of the built page tools scripts, such as the loader. It is not `/_vitehub/page`: Nitro answers 404 for
12
+ * any path under a public asset prefix that has no file, and gives the whole prefix the asset cache headers.
13
+ */
14
+ const viteHubPageToolsAssets = "/_vitehub/page/assets";
15
+ /** The route of the visitor check. */
16
+ const viteHubPageSessionPath = "/_vitehub/page/session";
17
+ /**
18
+ * The URL of the loader script, below the app base. Its version query changes when the loader changes, so caches keep
19
+ * it 5 minutes.
20
+ */
21
+ const viteHubPageToolsLoader = "/_vitehub/page/assets/loader.js?v=8";
22
+ /** The attribute of the script that loads the page tools. A page that has it does not get a second one. */
23
+ const viteHubPageToolsMarker = "data-vitehub-page-tools";
24
+ /** The generated SPA check's opening tag, so the server can recognize it when replacing the check. */
25
+ const viteHubPageToolsInlineStart = `<script type="module" ${viteHubPageToolsMarker}>`;
26
+ /** The exact generated SPA hint check, shared with the server's replacement check. */
27
+ function viteHubPageToolsInlineScript(base) {
28
+ const hint = `new URLSearchParams(location.search).has(${JSON.stringify(viteHubPageToolsQuery)})||document.cookie.split("; ").includes(${JSON.stringify(`${viteHubPageToolsCookie}=1`)})`;
29
+ return `${viteHubPageToolsInlineStart}if(${hint})import(${JSON.stringify(`${viteHubBasePath(base)}${viteHubPageToolsLoader}`)})<\/script>`;
30
+ }
31
+ /**
32
+ * The path of an app base, without the trailing slash: `/portal/` and `https://cdn.example/portal/` give `/portal`.
33
+ * The root and relative bases (`""`, `"./"`) give `""`. The Console mounts its routes with the same rule.
34
+ */
35
+ function viteHubBasePath(base) {
36
+ if (!base || base === "./") return "";
37
+ let pathname = base;
38
+ if (/^https?:\/\//.test(pathname)) try {
39
+ pathname = new URL(pathname).pathname;
40
+ } catch {
41
+ return "";
42
+ }
43
+ if (!pathname.startsWith("/") || pathname.startsWith("//")) return "";
44
+ return pathname.replace(/\/+$/, "");
45
+ }
46
+ /**
47
+ * Adds the app base to a path, such as the `script` of a tool. Full URLs and protocol-relative URLs stay as they are.
48
+ */
49
+ function withViteHubBase(base, path) {
50
+ return path.startsWith("/") && !path.startsWith("//") ? `${base}${path}` : path;
51
+ }
52
+ //#endregion
53
+ export { viteHubPageToolsInlineScript as a, viteHubPageToolsMarker as c, viteHubPageToolsCookie as i, viteHubPageToolsQuery as l, viteHubPageSessionPath as n, viteHubPageToolsInlineStart as o, viteHubPageToolsAssets as r, viteHubPageToolsLoader as s, viteHubBasePath as t, withViteHubBase as u };