@vite-hub/realtime 0.4.1 → 0.5.1

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 (43) hide show
  1. package/README.md +8 -4
  2. package/dist/agent.d.ts +1 -1
  3. package/dist/agent.js +1 -2
  4. package/dist/{bus-CKv8gQZf.js → bus-DJ3dOQAZ.js} +11 -22
  5. package/dist/{bus-protocol-wXkXW28q.d.ts → bus-protocol-juNrVJDF.d.ts} +0 -2
  6. package/dist/bus.d.ts +1 -3
  7. package/dist/bus.js +1 -2
  8. package/dist/client/browser.js +3 -3
  9. package/dist/client.d.ts +2 -4
  10. package/dist/client.js +15 -9
  11. package/dist/{conflict-DYC_qXzM.js → conflict-BqdKFrkE.js} +3 -5
  12. package/dist/{conflict-CmZizTYl.d.ts → conflict-C5KRv-J1.d.ts} +0 -2
  13. package/dist/{document-BfMW1zYU.d.ts → document-CbqgNO_0.d.ts} +2 -4
  14. package/dist/document-CfrQbB03.js +1736 -0
  15. package/dist/durability.d.ts +1 -3
  16. package/dist/durability.js +1 -6
  17. package/dist/{editor-BM5-vHqf.js → editor-DzhKM4Gt.js} +2 -5
  18. package/dist/{error-diagnostics-Cd-XWNf7.js → error-diagnostics-we8V1O-X.js} +1 -2
  19. package/dist/index.d.ts +3 -7
  20. package/dist/index.js +3 -3
  21. package/dist/internal/runtime/unavailable.d.ts +1 -3
  22. package/dist/internal/runtime/unavailable.js +1 -2
  23. package/dist/internal/server.d.ts +7 -0
  24. package/dist/internal/server.js +6 -0
  25. package/dist/{keepalive-B4ONG6AD.js → keepalive-BYkk6Ax8.js} +3 -5
  26. package/dist/{layout-DNaxppTZ.js → layout-BQwRLTH0.js} +1 -2
  27. package/dist/{layout-B7i6-FnH.d.ts → layout-BZtKNqiC.d.ts} +1 -3
  28. package/dist/log-NlQi6kow.js +157 -0
  29. package/dist/{object-BgPPDLDE.js → object-DfrneieE.js} +2 -4
  30. package/dist/{presence-B6rvkHqd.js → presence-DZ21pPKm.js} +3 -4
  31. package/dist/{request-C_bQc4NE.js → request-DM6xHTaU.js} +5 -10
  32. package/dist/{request-BwaohsJS.d.ts → request-PrMHOYFK.d.ts} +1 -3
  33. package/dist/server-CLdYV7Md.d.ts +126 -0
  34. package/dist/server-yQp02XNp.js +2599 -0
  35. package/dist/server.d.ts +4 -142
  36. package/dist/server.js +3 -2588
  37. package/dist/{types-Cvm0G3VJ.d.ts → types-oUyN-CJR.d.ts} +1 -27
  38. package/dist/vite.d.ts +4 -15
  39. package/dist/vite.js +64 -63
  40. package/dist/vue.d.ts +2 -7
  41. package/dist/vue.js +47 -40
  42. package/package.json +44 -39
  43. package/dist/document-U5rzg2vG.js +0 -2041
@@ -2,14 +2,11 @@ import { ResultError, ViteHubContext } from "@vite-hub/runtime";
2
2
  import { AnyExtension, JSONContent } from "@tiptap/core";
3
3
  import { WorkspaceAuthor, WorkspaceSnapshot } from "@vite-hub/workspace";
4
4
  import { H3Event } from "h3";
5
- //#region src/error-diagnostics.d.ts
6
5
  /** The `data` of a `REALTIME_REQUEST_FAILED` error. */
7
6
  type RealtimeRequestFailure = {
8
7
  /** HTTP status of the server answer, such as `409` when the stored document changed. `undefined` for a network error. */
9
8
  status: number | undefined;
10
9
  };
11
- //#endregion
12
- //#region src/types.d.ts
13
10
  /** JSON value stored in one field of a structured Realtime document. */
14
11
  type RealtimeFieldValue = null | boolean | number | string | RealtimeFieldValue[] | {
15
12
  [key: string]: RealtimeFieldValue;
@@ -175,14 +172,7 @@ interface RealtimePersistenceOptions {
175
172
  maxWait?: number;
176
173
  }
177
174
  interface RealtimeDefinitionIdentity {
178
- /** Resolve the user for a request, replacing the ViteHub Auth session. Return `null` for anonymous. */
179
175
  identify?: (context: RealtimeRequestContext) => RealtimeUser | null | undefined | Promise<RealtimeUser | null | undefined>;
180
- /**
181
- * Let a page on another origin connect, such as a script that sites load from the app. Return `true` to accept
182
- * `origin`. Without it, only the app's own origin or an origin trusted by Auth connects. The browser sends cookies with a cross-site handshake
183
- * too, so `identify` and `authorize` must then trust only what the page sends on purpose, such as a ticket in
184
- * `params`, never the session cookie. `authorize: true` without `identify` rejects it: the Auth session is a cookie.
185
- */
186
176
  origins?: (context: RealtimeOriginContext) => boolean | Promise<boolean>;
187
177
  }
188
178
  type RealtimeAuthorize = (context: RealtimeAuthorizeContext) => boolean | Promise<boolean>;
@@ -205,17 +195,12 @@ type RealtimeDefinitionAccess = RealtimeDefinitionIdentity & ({
205
195
  });
206
196
  interface RealtimeDocumentFields {
207
197
  document: RealtimeWorkspaceDocumentOptions | RealtimeDocumentAdapter;
208
- /**
209
- * Editor schema and Markdown codec. Defaults to the built-in Markdown kit. A function picks the codec of each
210
- * document, such as one per Content collection; browsers that open the document must use the same schema.
211
- */
212
- editor?: RealtimeEditor | ((context: RealtimeDocumentContext) => RealtimeEditor);
198
+ editor?: RealtimeEditor | ((context: RealtimeDocumentContext) => RealtimeEditor | Promise<RealtimeEditor>);
213
199
  history?: {
214
200
  checkpoint: true | {
215
201
  message?: string;
216
202
  };
217
203
  };
218
- /** Idle saves. `false` saves only when a client calls `save()` or `history.checkpoint()`. */
219
204
  persistence?: RealtimePersistenceOptions | false;
220
205
  }
221
206
  /** A definition whose rooms edit one stored document each. */
@@ -225,17 +210,7 @@ interface RealtimePresenceFields {
225
210
  editor?: never;
226
211
  history?: never;
227
212
  persistence?: never;
228
- /**
229
- * Lets server code ask the one browser in a room with `requestRealtimeRoom()` from `@vite-hub/realtime/server`. The
230
- * browser answers with `room.onRequest()`. Default `false`: rooms without it refuse request frames.
231
- */
232
213
  requests?: boolean;
233
- /**
234
- * `"user"`: each person gets their own rooms. A room is keyed by the identity of whoever joins it, so the same room id
235
- * for two people is two rooms, and `requestRealtimeRoom()` must name the person with `{ user }`. The identity is the
236
- * ViteHub Auth session when the app has Auth, read without requiring one; everyone without a session shares one
237
- * `anonymous` scope. With `identify` or `authorize: true`, those decide the identity.
238
- */
239
214
  scope?: "user";
240
215
  }
241
216
  /**
@@ -326,5 +301,4 @@ type RealtimeAvailability = {
326
301
  reason: string;
327
302
  fix: string;
328
303
  };
329
- //#endregion
330
304
  export { RealtimeResetReason as A, RealtimeReadOnlyReason as C, RealtimeRequestErrorCode as D, RealtimeRequestError as E, RealtimeUser as F, RealtimeVerifyResult as I, RealtimeWorkspaceChange as L, RealtimeSaveOptions as M, RealtimeSaveResult as N, RealtimeRequestEvent as O, RealtimeSaved as P, RealtimeWorkspaceDocumentOptions as R, RealtimePresenceDefinition as S, RealtimeRequestContext as T, RealtimeLoadedDocument as _, RealtimeDefinition as a, RealtimePersistenceOptions as b, RealtimeDocumentContext as c, RealtimeDocumentStatus as d, RealtimeEditor as f, RealtimeIssue as g, RealtimeHoldOptions as h, RealtimeCheckpoint as i, RealtimeRoomRequestErrorCode as j, RealtimeRequestResult as k, RealtimeDocumentDefinition as l, RealtimeHistoryOptions as m, RealtimeAuthorizeContext as n, RealtimeDefinitionAccess as o, RealtimeFieldValue as p, RealtimeAvailability as r, RealtimeDocumentAdapter as s, DiscoveredRealtimeDefinition as t, RealtimeDocumentSnapshot as u, RealtimeOptions as v, RealtimeRegistry as w, RealtimePerson as x, RealtimeOriginContext as y, RealtimeRequestFailure as z };
package/dist/vite.d.ts CHANGED
@@ -1,13 +1,8 @@
1
- import { t as DiscoveredRealtimeDefinition, v as RealtimeOptions } from "./types-Cvm0G3VJ.js";
1
+ import { t as DiscoveredRealtimeDefinition, v as RealtimeOptions } from "./types-oUyN-CJR.js";
2
2
  import { Plugin } from "vite";
3
- //#region src/discovery.d.ts
4
3
  export declare function discoverRealtimeDefinitions(rootDir: string, serverDirs?: string[]): DiscoveredRealtimeDefinition[];
5
- //#endregion
6
- //#region ../internal/src/deployment.d.ts
7
4
  /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
8
5
  type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
9
- //#endregion
10
- //#region ../internal/src/inspect.d.ts
11
6
  interface ViteHubDefinitionField {
12
7
  label: string;
13
8
  value: string;
@@ -57,6 +52,8 @@ interface ViteHubResourceSummary {
57
52
  owner: string;
58
53
  /** Absent when no id is known yet. */
59
54
  source?: ViteHubResourceIdSource;
55
+ /** The resource is in the Wrangler config of a standalone Provider Output Worker, not in Nitro's. */
56
+ standalone?: boolean;
60
57
  }
61
58
  interface ViteHubInspectionContributor {
62
59
  definitions?: readonly ViteHubDefinitionInspector[];
@@ -67,8 +64,6 @@ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor |
67
64
  interface ViteHubInspectionPluginMetadata {
68
65
  inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
69
66
  }
70
- //#endregion
71
- //#region ../internal/src/build/deployment-plan-output.d.ts
72
67
  /**
73
68
  * One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
74
69
  * a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
@@ -98,8 +93,6 @@ interface DeploymentEnvContext {
98
93
  * Return names only, never values.
99
94
  */
100
95
  type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
101
- //#endregion
102
- //#region ../internal/src/durability.d.ts
103
96
  /**
104
97
  * One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
105
98
  * imports `export` from `module` at boot and calls it with `input` and the server environment. It returns the
@@ -122,11 +115,7 @@ interface DurabilityPluginMetadata {
122
115
  /** Called after Vite resolves the config. Return an empty list when the primitive is off. */
123
116
  durability?: () => readonly DurabilityContribution[];
124
117
  }
125
- //#endregion
126
- //#region src/inspect.d.ts
127
118
  type RealtimeInspectionDriver = "auto" | "cloudflare" | "memory" | "node" | "postgres" | "redis" | "unsupported";
128
- //#endregion
129
- //#region src/vite.d.ts
130
119
  /** Where a contributed definition runs. */
131
120
  export interface RealtimeContributionContext {
132
121
  /**
@@ -178,4 +167,4 @@ export interface RealtimeInspectionOptions {
178
167
  */
179
168
  export declare function inspectRealtimeDefinitions(options: RealtimeInspectionOptions): Promise<ViteHubDefinitionSummary[]>;
180
169
  export declare function hubRealtime(options?: RealtimeVitePluginOptions): RealtimeVitePlugin;
181
- //#endregion
170
+ export {};
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
- import { t as realtimeErrorDiagnostics } from "./error-diagnostics-Cd-XWNf7.js";
2
- import { o as realtimeNamespaceVariable, s as realtimePostgresUrlVariable } from "./bus-CKv8gQZf.js";
3
- import { g as realtimeKeepalivePong, h as realtimeKeepalivePing, r as isRecordOrFunction, t as cloneRecord } from "./object-BgPPDLDE.js";
1
+ import { g as realtimeKeepalivePong, h as realtimeKeepalivePing, r as isRecordOrFunction, t as cloneRecord } from "./object-DfrneieE.js";
2
+ import { o as realtimeNamespaceVariable, s as realtimePostgresUrlVariable } from "./bus-DJ3dOQAZ.js";
3
+ import { t as realtimeErrorDiagnostics } from "./error-diagnostics-we8V1O-X.js";
4
4
  import availability from "./internal/runtime/unavailable.js";
5
5
  import { defineDiagnostics } from "nostics";
6
6
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
@@ -8,7 +8,7 @@ import { mkdir, writeFile } from "node:fs/promises";
8
8
  import { basename, dirname, parse, relative, resolve } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
10
  import { tmpdir } from "node:os";
11
- //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
11
+ // ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
12
12
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
13
13
  function normalizeWindowsPath(input = "") {
14
14
  if (!input) return input;
@@ -99,8 +99,7 @@ const relative$1 = function(from, to) {
99
99
  }
100
100
  return [..._from.map(() => ".."), ..._to].join("/");
101
101
  };
102
- //#endregion
103
- //#region ../internal/src/error-diagnostics.ts
102
+ // ../internal/src/error-diagnostics.ts
104
103
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
105
104
  const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
106
105
  docsBase: "https://vitehub.dev/docs/development/diagnostics",
@@ -126,7 +125,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
126
125
  why: ({ message }) => message === void 0 ? "" : String(message)
127
126
  },
128
127
  INTERNAL_R0022: {
129
- fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
128
+ fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
130
129
  why: ({ message }) => message === void 0 ? "" : String(message)
131
130
  },
132
131
  INTERNAL_R0024: {
@@ -345,6 +344,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
345
344
  why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
346
345
  fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
347
346
  },
347
+ INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
348
+ why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
349
+ fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
350
+ },
348
351
  INTERNAL_SECRET_PURPOSE_MISSING: {
349
352
  why: "[vitehub] A derived secret requires a purpose.",
350
353
  fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
@@ -353,6 +356,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
353
356
  why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
354
357
  fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
355
358
  },
359
+ INTERNAL_SITE_TOKEN_TOO_LONG: {
360
+ why: ({ length, maximum }) => `The Site access token is ${length} characters, and an app accepts ${maximum}.`,
361
+ fix: "Open the app with a shorter path, or give the person and the project shorter names, so that the Site access token fits."
362
+ },
356
363
  INTERNAL_SQLITE_ARGUMENT_INVALID: {
357
364
  why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
358
365
  fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
@@ -367,8 +374,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
367
374
  }
368
375
  }
369
376
  });
370
- //#endregion
371
- //#region ../internal/src/definition-catalog.ts
377
+ // ../internal/src/definition-catalog.ts
372
378
  const sourceFilePattern = /\.(?:c|m)?[jt]sx?$/i;
373
379
  const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
374
380
  const testFilePattern = /\.(?:test|spec)\.(?:c|m)?[jt]sx?$/i;
@@ -500,22 +506,19 @@ function createRuntimeRegistryContents(registryFile, definitions) {
500
506
  ""
501
507
  ].join("\n");
502
508
  }
503
- //#endregion
504
- //#region ../internal/src/durability.ts
509
+ // ../internal/src/durability.ts
505
510
  /** The `durability` module next to the Vite plugin module at `importMetaUrl`, in source and in `dist`. */
506
511
  function durabilityModuleFile(importMetaUrl) {
507
512
  return fileURLToPath(new URL(importMetaUrl.endsWith(".ts") ? "./durability.ts" : "./durability.js", importMetaUrl));
508
513
  }
509
- //#endregion
510
- //#region ../internal/src/inspect.ts
514
+ // ../internal/src/inspect.ts
511
515
  function relativeDefinitionFile(projectRoot, file) {
512
516
  return relative$1(projectRoot, file).replaceAll("\\", "/");
513
517
  }
514
518
  const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
515
519
  new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
516
520
  new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
517
- //#endregion
518
- //#region ../internal/src/build/vite.ts
521
+ // ../internal/src/build/vite.ts
519
522
  const projectRootDirectoryMarkers = [
520
523
  ["server", "agents"],
521
524
  ["server", "channels"],
@@ -568,7 +571,7 @@ function hasProjectRootDirectoryMarker(root) {
568
571
  for (const marker of projectRootDirectoryMarkers) try {
569
572
  if (statSync(resolve(root, ...marker)).isDirectory()) return true;
570
573
  } catch (error) {
571
- if (error.code !== "ENOENT") throw error;
574
+ if (!isMissingProjectMarker(error)) throw error;
572
575
  }
573
576
  return false;
574
577
  }
@@ -582,11 +585,16 @@ function hasProjectRootFileMarker(root, markers) {
582
585
  try {
583
586
  if (statSync(resolve(root, ...path)).isFile()) return true;
584
587
  } catch (error) {
585
- if (error.code !== "ENOENT") throw error;
588
+ if (!isMissingProjectMarker(error)) throw error;
586
589
  }
587
590
  }
588
591
  return false;
589
592
  }
593
+ function isMissingProjectMarker(error) {
594
+ const code = error.code;
595
+ return code === "ENOENT" || code === "ENOTDIR";
596
+ }
597
+ // ../internal/src/runtime/page-tools-shared.ts
590
598
  /**
591
599
  * The path of an app base, without the trailing slash: `/portal/` and `https://cdn.example/portal/` give `/portal`.
592
600
  * The root and relative bases (`""`, `"./"`) give `""`. The Console mounts its routes with the same rule.
@@ -602,35 +610,15 @@ function viteHubBasePath(base) {
602
610
  if (!pathname.startsWith("/") || pathname.startsWith("//")) return "";
603
611
  return pathname.replace(/\/+$/, "");
604
612
  }
605
- //#endregion
606
- //#region ../internal/src/build/page-tools.ts
607
- function readString(value, key) {
608
- const field = value !== null && typeof value === "object" ? Reflect.get(value, key) : void 0;
609
- return typeof field === "string" ? field : void 0;
610
- }
613
+ Object.freeze({ vitehubAuthAccess: "handler" });
611
614
  /**
612
- * The app base of a Vite configuration. ViteHub's application-base config field or `__VITEHUB_APP_BASE_URL__` constant
613
- * takes precedence over the Vite `base`; the Nuxt module sets both from `app.baseURL`. Only a root-relative Vite `base`
614
- * supplies an application path; absolute and protocol-relative URLs are asset CDN bases. The Nitro base is
615
- * `nitro.baseURL`, else `NITRO_APP_BASE_URL`.
615
+ * The route meta of a generated handler that checks access on every request, even when the app adds no rule: a required
616
+ * `authorize` policy, an explicit `access` rule, a required access token, or a signature. Auth access routes still apply
617
+ * to it, so an app rule stays in force. `checksOwnAccess(event)` of `vite-hub/auth` reads it, so app middleware can skip
618
+ * the route. A route that can run without a check, such as a browser error sink, an optional `authorize`, or a webhook
619
+ * with `secret: false`, must not use it.
616
620
  */
617
- function viteHubPageToolsBase(config, env = process.env) {
618
- const defined = readString(config !== null && typeof config === "object" ? Reflect.get(config, "define") : void 0, "__VITEHUB_APP_BASE_URL__");
619
- const viteBase = readString(config, "base");
620
- let appBase = viteBase?.startsWith("/") && !viteBase.startsWith("//") ? viteBase : void 0;
621
- if (defined) try {
622
- const value = JSON.parse(defined);
623
- if (typeof value === "string") appBase = value;
624
- } catch {}
625
- const base = viteHubBasePath(readString(config, "__vitehubAppBaseURL") ?? appBase);
626
- const nitroBase = viteHubBasePath(readString(config !== null && typeof config === "object" ? Reflect.get(config, "nitro") : void 0, "baseURL") ?? env.NITRO_APP_BASE_URL);
627
- return {
628
- base,
629
- mount: nitroBase && (base === nitroBase || base.startsWith(`${nitroBase}/`)) ? base.slice(nitroBase.length) : base
630
- };
631
- }
632
- //#endregion
633
- //#region ../internal/src/nitro-kit.ts
621
+ const ownAccessRouteMeta = Object.freeze({ vitehubOwnAccess: true });
634
622
  function cloneArray(value) {
635
623
  return Array.isArray(value) ? [...value] : [];
636
624
  }
@@ -658,6 +646,32 @@ function createNitroServerKit(value = {}) {
658
646
  }
659
647
  };
660
648
  }
649
+ // ../internal/src/build/page-tools.ts
650
+ function readString(value, key) {
651
+ const field = value !== null && typeof value === "object" ? Reflect.get(value, key) : void 0;
652
+ return typeof field === "string" ? field : void 0;
653
+ }
654
+ /**
655
+ * The app base of a Vite configuration. ViteHub's application-base config field or `__VITEHUB_APP_BASE_URL__` constant
656
+ * takes precedence over the Vite `base`; the Nuxt module sets both from `app.baseURL`. Only a root-relative Vite `base`
657
+ * supplies an application path; absolute and protocol-relative URLs are asset CDN bases. The Nitro base is
658
+ * `nitro.baseURL`, else `NITRO_APP_BASE_URL`.
659
+ */
660
+ function viteHubPageToolsBase(config, env = process.env) {
661
+ const defined = readString(config !== null && typeof config === "object" ? Reflect.get(config, "define") : void 0, "__VITEHUB_APP_BASE_URL__");
662
+ const viteBase = readString(config, "base");
663
+ let appBase = viteBase?.startsWith("/") && !viteBase.startsWith("//") ? viteBase : void 0;
664
+ if (defined) try {
665
+ const value = JSON.parse(defined);
666
+ if (typeof value === "string") appBase = value;
667
+ } catch {}
668
+ const base = viteHubBasePath(readString(config, "__vitehubAppBaseURL") ?? appBase);
669
+ const nitroBase = viteHubBasePath(readString(config !== null && typeof config === "object" ? Reflect.get(config, "nitro") : void 0, "baseURL") ?? env.NITRO_APP_BASE_URL);
670
+ return {
671
+ base,
672
+ mount: nitroBase && (base === nitroBase || base.startsWith(`${nitroBase}/`)) ? base.slice(nitroBase.length) : base
673
+ };
674
+ }
661
675
  /** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
662
676
  function hostFromNitroPreset(value) {
663
677
  const normalized = value?.trim().toLowerCase().replaceAll("_", "-");
@@ -668,8 +682,7 @@ function hostFromNitroPreset(value) {
668
682
  if (normalized === "node" || normalized.startsWith("node-")) return "node";
669
683
  if (normalized.startsWith("vercel")) return "vercel";
670
684
  }
671
- //#endregion
672
- //#region ../internal/src/hosting.ts
685
+ // ../internal/src/hosting.ts
673
686
  /**
674
687
  * Returns the Nitro preset name that this build targets, as the developer wrote it.
675
688
  * The order is `nitro.preset`, `hosting`, `NITRO_PRESET`, `SERVER_PRESET`, then `VITEHUB_HOST`.
@@ -695,8 +708,7 @@ function getHostingProvider(hosting) {
695
708
  const host = hostFromNitroPreset(hosting);
696
709
  if (host === "cloudflare" || host === "netlify" || host === "vercel") return host;
697
710
  }
698
- //#endregion
699
- //#region src/deployment-env.ts
711
+ // src/deployment-env.ts
700
712
  const owners = ["realtime"];
701
713
  function entry(names, required, secret, hasDefault = false) {
702
714
  return {
@@ -723,8 +735,7 @@ function realtimeDeploymentEnv(input, context) {
723
735
  namespace
724
736
  ];
725
737
  }
726
- //#endregion
727
- //#region src/discovery.ts
738
+ // src/discovery.ts
728
739
  function discoverRealtimeDefinitions(rootDir, serverDirs) {
729
740
  return discoverDefinitions("realtime", [createDirectoryDefinitionSource("server-realtime", serverDirs ?? [resolve(rootDir, "server")], "realtime", {
730
741
  createDefinition: ({ file, name }) => ({
@@ -735,8 +746,7 @@ function discoverRealtimeDefinitions(rootDir, serverDirs) {
735
746
  normalizeName: normalizePathDefinitionName
736
747
  })]);
737
748
  }
738
- //#endregion
739
- //#region src/inspect.ts
749
+ // src/inspect.ts
740
750
  const driverLabels = {
741
751
  auto: "auto: Cloudflare Durable Objects on Cloudflare, memory in development, shared rooms on a Node server, build error elsewhere",
742
752
  cloudflare: "cloudflare: one Durable Object per document, Yjs state in SQLite",
@@ -805,7 +815,6 @@ function describePersistence(node) {
805
815
  } else if (node) return "dynamic";
806
816
  return `idle save after ${debounce} ms (at most ${maxWait} ms) and when the last client leaves`;
807
817
  }
808
- /** Reads the static shape of one Realtime Definition file without executing it. */
809
818
  function describeRealtimeDefinitionSource(parse, file, source) {
810
819
  let object;
811
820
  let builder;
@@ -883,8 +892,7 @@ async function summarizeRealtimeDefinitions(projectRoot, definitions, driver) {
883
892
  };
884
893
  });
885
894
  }
886
- //#endregion
887
- //#region src/vite.ts
895
+ // src/vite.ts
888
896
  /**
889
897
  * Lists Realtime Definitions with their document adapter, editor codec, identity, authorization,
890
898
  * persistence, and driver, read statically from each definition file.
@@ -911,7 +919,6 @@ function configureCloudflareRealtime(nitro) {
911
919
  cloudflare.wrangler = wrangler;
912
920
  nitro.cloudflare = cloudflare;
913
921
  }
914
- /** Packages that share the Yjs runtime on the server. They must load as one module graph. */
915
922
  const realtimeServerYjsPackages = [
916
923
  "yjs",
917
924
  "y-protocols",
@@ -934,14 +941,9 @@ function findDatabasePlugin(plugins) {
934
941
  if (found) return found;
935
942
  } else if (plugin && typeof plugin === "object" && "name" in plugin && plugin.name === databaseVitePluginName) return plugin;
936
943
  }
937
- /** Whether the Database integration resolved the Default Database on Postgres. The Postgres bus then uses its client. */
938
944
  function hasPostgresDefaultDatabase(plugin) {
939
945
  return plugin?.api?.getConfig?.()?.databases.default?.dialect === "postgresql";
940
946
  }
941
- /**
942
- * The handler and the Nitro plugin of a Node build. `database` is the module that exports the app's `databases`, when
943
- * the Default Database is on Postgres: the bus then borrows the postgres.js client of that Database.
944
- */
945
947
  function renderNodeFiles(input) {
946
948
  const { busPlugin, database, handlerFile, importBase, namespace, nodeDriver, registryFile } = input;
947
949
  const busOptions = `, { ${database ? `databases: () => import(${JSON.stringify(database)}).then(module => module.databases), ` : ""}namespace: ${JSON.stringify(namespace)} }`;
@@ -970,7 +972,6 @@ function renderNodeFiles(input) {
970
972
  ""
971
973
  ].join("\n")]];
972
974
  }
973
- /** The app name: the `name` in the root `package.json`, else the root folder name. */
974
975
  function defaultNamespace(root) {
975
976
  try {
976
977
  const name = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8")).name;
@@ -1127,6 +1128,7 @@ function hubRealtime(options = {}) {
1127
1128
  kit.addHandler({
1128
1129
  handler: handlerFile,
1129
1130
  lazy: true,
1131
+ meta: { ...ownAccessRouteMeta },
1130
1132
  route: `${mount}/_vitehub/realtime/**`
1131
1133
  });
1132
1134
  if (durablePlugin) kit.addPlugin(durablePlugin);
@@ -1162,5 +1164,4 @@ function hubRealtime(options = {}) {
1162
1164
  }
1163
1165
  };
1164
1166
  }
1165
- //#endregion
1166
1167
  export { discoverRealtimeDefinitions, hubRealtime, inspectRealtimeDefinitions };
package/dist/vue.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { A as RealtimeResetReason, C as RealtimeReadOnlyReason, D as RealtimeRequestErrorCode, E as RealtimeRequestError, F as RealtimeUser, L as RealtimeWorkspaceChange, P as RealtimeSaved, d as RealtimeDocumentStatus, f as RealtimeEditor, i as RealtimeCheckpoint, k as RealtimeRequestResult, x as RealtimePerson, z as RealtimeRequestFailure } from "./types-Cvm0G3VJ.js";
2
- import { i as readRealtimeYDoc } from "./document-BfMW1zYU.js";
1
+ import { A as RealtimeResetReason, C as RealtimeReadOnlyReason, D as RealtimeRequestErrorCode, E as RealtimeRequestError, F as RealtimeUser, L as RealtimeWorkspaceChange, P as RealtimeSaved, d as RealtimeDocumentStatus, f as RealtimeEditor, i as RealtimeCheckpoint, k as RealtimeRequestResult, x as RealtimePerson, z as RealtimeRequestFailure } from "./types-oUyN-CJR.js";
2
+ import { i as readRealtimeYDoc } from "./document-CbqgNO_0.js";
3
3
  import { Awareness } from "y-protocols/awareness";
4
4
  import { WebsocketProvider } from "y-websocket";
5
5
  import * as Y from "yjs";
6
6
  import { AnyExtension, Extension } from "@tiptap/core";
7
7
  import { MaybeRefOrGetter, Ref } from "vue";
8
8
  import { DecorationAttrs } from "@tiptap/pm/view";
9
- //#region src/caret.d.ts
10
9
  /** A remote person as the caret sees them: the presence identity from awareness. */
11
10
  interface RealtimeCaretUser {
12
11
  color: string;
@@ -26,8 +25,6 @@ interface RealtimeCaretOptions {
26
25
  * Realtime has its own copy, cannot find Realtime's sync plugin, and draws nothing. Presence identity stays Realtime's.
27
26
  */
28
27
  export declare const RealtimeCaret: Extension<RealtimeCaretOptions, any>;
29
- //#endregion
30
- //#region src/vue.d.ts
31
28
  export type RealtimeStatus = "connected" | "connecting" | "disconnected";
32
29
  export interface RealtimeResetEvent {
33
30
  /** Room seed the client reconnects to. */
@@ -60,7 +57,6 @@ export declare function useRealtimeTiptap(definition: string, documentId: MaybeR
60
57
  fields: import("vue").ComputedRef<Y.Map<unknown> | undefined>;
61
58
  people: import("vue").ShallowRef<RealtimePerson[], RealtimePerson[]>;
62
59
  provider: import("vue").ShallowRef<WebsocketProvider | undefined, WebsocketProvider | undefined>;
63
- /** The server rejects edits from this connection. `readOnlyReason` tells why; `saveStatus` holds the details. */
64
60
  readOnly: import("vue").ComputedRef<boolean>;
65
61
  readOnlyReason: Ref<RealtimeReadOnlyReason | null, RealtimeReadOnlyReason | null>;
66
62
  refresh: () => Promise<RealtimeRequestResult<{
@@ -83,5 +79,4 @@ export declare function useRealtimeTiptap(definition: string, documentId: MaybeR
83
79
  };
84
80
  destroy: () => void;
85
81
  };
86
- //#endregion
87
82
  export { type RealtimeCaretOptions, type RealtimeCaretUser, type RealtimeRequestError, type RealtimeRequestErrorCode, type RealtimeRequestFailure, type RealtimeRequestResult, readRealtimeYDoc };