@vite-hub/realtime 0.1.0 → 0.3.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.
- package/README.md +71 -12
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +2 -0
- package/dist/bus-Bi-Ec414.js +476 -0
- package/dist/bus-protocol-wXkXW28q.d.ts +66 -0
- package/dist/bus.d.ts +85 -0
- package/dist/bus.js +2 -0
- package/dist/client/browser.js +53 -0
- package/dist/client.d.ts +25 -4
- package/dist/client.js +66 -8
- package/dist/conflict-Bg8vCisd.js +63 -0
- package/dist/{document-CtY6umWY.d.ts → document-DPaywuCO.d.ts} +2 -2
- package/dist/{document-BFaqcCAL.js → document-DjBrcgpY.js} +22 -10
- package/dist/durability.d.ts +10 -0
- package/dist/durability.js +46 -0
- package/dist/{layout-Br1aOL7o.js → editor-BM5-vHqf.js} +30 -36
- package/dist/error-diagnostics-B_66irmt.js +141 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +3 -7
- package/dist/internal/runtime/unavailable.d.ts +5 -0
- package/dist/internal/runtime/unavailable.js +8 -0
- package/dist/keepalive-BCs-uXp4.js +33 -0
- package/dist/layout-DNaxppTZ.js +34 -0
- package/dist/{layout-WNWejwOY.d.ts → layout-fyQnhwCg.d.ts} +1 -1
- package/dist/{protocol-9ZDLEcSS.js → object-CzKyK0hX.js} +57 -58
- package/dist/presence-Tuy1y_l9.js +53 -0
- package/dist/request-BUwa359H.d.ts +48 -0
- package/dist/request-CWaHqW3R.js +192 -0
- package/dist/server.d.ts +64 -28
- package/dist/server.js +1002 -379
- package/dist/{types-Bw6-42Se.d.ts → types-1DVVG5ro.d.ts} +118 -14
- package/dist/vite.d.ts +109 -12
- package/dist/vite.js +469 -138
- package/dist/vue.d.ts +8 -5
- package/dist/vue.js +25 -11
- package/package.json +71 -19
- package/dist/application-path-CJblgbWK.js +0 -6
- package/dist/conflict-rguoaHlE.js +0 -34
- package/dist/durable-key-tnSw58ZK.js +0 -8
- package/dist/error-diagnostics-Cvm6vRXQ.js +0 -73
package/dist/vue.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as readRealtimeYDoc } from "./document-
|
|
1
|
+
import { C as RealtimeReadOnlyReason, E as RealtimeRequestErrorCode, F as RealtimeWorkspaceChange, M as RealtimeSaved, N as RealtimeUser, O as RealtimeResetReason, d as RealtimeDocumentStatus, f as RealtimeEditor, i as RealtimeCheckpoint, x as RealtimePerson } from "./types-1DVVG5ro.js";
|
|
2
|
+
import { i as readRealtimeYDoc } from "./document-DPaywuCO.js";
|
|
3
|
+
import { Result } from "@vite-hub/runtime";
|
|
3
4
|
import { Awareness } from "y-protocols/awareness";
|
|
4
5
|
import { WebsocketProvider } from "y-websocket";
|
|
5
6
|
import * as Y from "yjs";
|
|
6
|
-
import { Result } from "@vite-hub/runtime";
|
|
7
7
|
import { AnyExtension, Extension } from "@tiptap/core";
|
|
8
8
|
import { MaybeRefOrGetter, Ref } from "vue";
|
|
9
9
|
import { DecorationAttrs } from "@tiptap/pm/view";
|
|
@@ -39,8 +39,11 @@ export interface RealtimeResetEvent {
|
|
|
39
39
|
reason: RealtimeResetReason;
|
|
40
40
|
}
|
|
41
41
|
export interface UseRealtimeTiptapOptions {
|
|
42
|
-
/**
|
|
43
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Editor schema shared with the definition's `editor`. Defaults to the built-in Markdown kit. Its `version` goes with
|
|
44
|
+
* the connection: when it differs from the server's, the connection is read-only with `readOnlyReason` `version`.
|
|
45
|
+
*/
|
|
46
|
+
editor?: Pick<RealtimeEditor, "extensions" | "version">;
|
|
44
47
|
enabled?: MaybeRefOrGetter<boolean>;
|
|
45
48
|
/** Presence identity. Defaults to the ViteHub Auth session; pass `null` for an anonymous guest. */
|
|
46
49
|
identity?: MaybeRefOrGetter<RealtimeUser | null | undefined>;
|
package/dist/vue.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as realtimeDocumentLayout,
|
|
5
|
-
import {
|
|
1
|
+
import { t as realtimeErrorDiagnostics } from "./error-diagnostics-B_66irmt.js";
|
|
2
|
+
import { n as resolveRealtimeApplicationPath, t as keepRealtimeSocketAlive } from "./keepalive-BCs-uXp4.js";
|
|
3
|
+
import { i as decodeRealtimeControlPayload, l as encodeWorkspaceChange, n as isRecord, o as decodeWorkspaceChangePayload, u as isRetryableRealtimeRequestCode, x as workspaceRoomId } from "./object-CzKyK0hX.js";
|
|
4
|
+
import { n as realtimeDocumentLayout, t as readRealtimeStatus } from "./layout-DNaxppTZ.js";
|
|
5
|
+
import { n as getRealtimePeople, t as createRealtimeIdentity } from "./presence-Tuy1y_l9.js";
|
|
6
|
+
import { t as createRealtimeEditorExtensions } from "./editor-BM5-vHqf.js";
|
|
7
|
+
import { _ as yCursorPlugin, b as yUndoPlugin, f as absolutePositionToRelativePosition, g as undo, h as relativePositionToAbsolutePosition, m as redo, o as readRealtimeYDoc, p as defaultSelectionBuilder, v as ySyncPlugin, x as yUndoPluginKey, y as ySyncPluginKey } from "./document-DjBrcgpY.js";
|
|
6
8
|
import "lib0/decoding";
|
|
7
9
|
import * as encoding from "lib0/encoding";
|
|
8
10
|
import * as awarenessProtocol from "y-protocols/awareness";
|
|
@@ -11,7 +13,7 @@ import * as Y from "yjs";
|
|
|
11
13
|
import { Extension, MappablePosition, getUpdatedPosition } from "@tiptap/core";
|
|
12
14
|
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
13
15
|
import { useUserSession } from "@vite-hub/auth/vue";
|
|
14
|
-
import { computed, markRaw, onScopeDispose, ref, shallowRef, toValue, watch } from "vue";
|
|
16
|
+
import { computed, getCurrentInstance, markRaw, onMounted, onScopeDispose, ref, shallowRef, toValue, watch } from "vue";
|
|
15
17
|
//#region ../../node_modules/.pnpm/@tiptap+extension-collaboration@3.31.4_@tiptap+core@3.31.4_@tiptap+pm@3.31.4__@tiptap+p_85015a5a825a0d4859fbb90094e145d9/node_modules/@tiptap/extension-collaboration/dist/index.js
|
|
16
18
|
/**
|
|
17
19
|
* Checks if a transaction was originated from a Yjs change.
|
|
@@ -238,9 +240,6 @@ const RealtimeCaret = Extension.create({
|
|
|
238
240
|
//#endregion
|
|
239
241
|
//#region src/vue.ts
|
|
240
242
|
const workspaceChangeFlushIntervalMs = 11;
|
|
241
|
-
function isRecord(value) {
|
|
242
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
243
|
-
}
|
|
244
243
|
function isString(value) {
|
|
245
244
|
return typeof value === "string";
|
|
246
245
|
}
|
|
@@ -304,6 +303,7 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
|
|
|
304
303
|
let connectedDocumentId;
|
|
305
304
|
let workspaceChangeTimer;
|
|
306
305
|
const enabled = () => options.enabled === void 0 || toValue(options.enabled);
|
|
306
|
+
let canConnect = !getCurrentInstance();
|
|
307
307
|
function destroyDocument(keepDocument = false, preserveRefresh = false) {
|
|
308
308
|
for (const controller of requestControllers) if (!preserveRefresh || !refreshControllers.has(controller)) controller.abort();
|
|
309
309
|
if (preserveRefresh) {
|
|
@@ -373,6 +373,7 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
|
|
|
373
373
|
params: { workspace: "events" }
|
|
374
374
|
});
|
|
375
375
|
nextWorkspaceProvider.awareness.setLocalState(null);
|
|
376
|
+
keepRealtimeSocketAlive(nextWorkspaceProvider);
|
|
376
377
|
nextWorkspaceProvider.messageHandlers[4] = (_encoder, decoder) => {
|
|
377
378
|
const change = decodeWorkspaceChangePayload(decoder);
|
|
378
379
|
if (change) workspaceChange.value = change;
|
|
@@ -385,10 +386,16 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
|
|
|
385
386
|
function connect(id) {
|
|
386
387
|
const nextDocument = markRaw(new Y.Doc());
|
|
387
388
|
const room = id.split("/").map(encodeURIComponent).join("/");
|
|
389
|
+
const version = options.editor?.version;
|
|
388
390
|
const nextProvider = new WebsocketProvider(serverURL(), room, nextDocument, {
|
|
391
|
+
connect: canConnect,
|
|
389
392
|
disableBc: true,
|
|
390
|
-
params: {
|
|
393
|
+
params: {
|
|
394
|
+
clientId: String(nextDocument.clientID),
|
|
395
|
+
...version === void 0 ? {} : { editor: version }
|
|
396
|
+
}
|
|
391
397
|
});
|
|
398
|
+
keepRealtimeSocketAlive(nextProvider);
|
|
392
399
|
nextProvider.messageHandlers[5] = (_encoder, decoder) => {
|
|
393
400
|
if (provider.value !== nextProvider) return;
|
|
394
401
|
const control = decodeRealtimeControlPayload(decoder);
|
|
@@ -433,7 +440,7 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
|
|
|
433
440
|
connectedDocumentId = id;
|
|
434
441
|
document.value = nextDocument;
|
|
435
442
|
provider.value = nextProvider;
|
|
436
|
-
status.value = "connecting";
|
|
443
|
+
if (canConnect) status.value = "connecting";
|
|
437
444
|
}
|
|
438
445
|
function reset(id, reason, epoch) {
|
|
439
446
|
const previous = document.value;
|
|
@@ -551,6 +558,13 @@ function useRealtimeTiptap(definition, documentId, options = {}) {
|
|
|
551
558
|
if (!active || !id || typeof window === "undefined") return;
|
|
552
559
|
connect(id);
|
|
553
560
|
}, { immediate: true });
|
|
561
|
+
if (!canConnect) onMounted(() => {
|
|
562
|
+
canConnect = true;
|
|
563
|
+
const current = provider.value;
|
|
564
|
+
if (!current) return;
|
|
565
|
+
status.value = "connecting";
|
|
566
|
+
current.connect();
|
|
567
|
+
});
|
|
554
568
|
watch(enabled, (active) => {
|
|
555
569
|
const current = workspaceProvider.value;
|
|
556
570
|
if (!current) return;
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/realtime",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Realtime document primitives and Vite integration for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"collaboration",
|
|
7
7
|
"h3",
|
|
8
|
+
"postgres",
|
|
8
9
|
"realtime",
|
|
10
|
+
"redis",
|
|
9
11
|
"typescript",
|
|
10
12
|
"vite",
|
|
11
13
|
"vitehub",
|
|
@@ -28,17 +30,43 @@
|
|
|
28
30
|
"type": "module",
|
|
29
31
|
"sideEffects": false,
|
|
30
32
|
"types": "./dist/index.d.ts",
|
|
33
|
+
"imports": {
|
|
34
|
+
"#vitehub/realtime/availability": {
|
|
35
|
+
"types": "./dist/internal/runtime/unavailable.d.ts",
|
|
36
|
+
"default": "./dist/internal/runtime/unavailable.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
31
39
|
"exports": {
|
|
32
40
|
".": {
|
|
33
41
|
"types": "./dist/index.d.ts",
|
|
34
42
|
"import": "./dist/index.js",
|
|
35
43
|
"default": "./dist/index.js"
|
|
36
44
|
},
|
|
45
|
+
"./agent": {
|
|
46
|
+
"types": "./dist/agent.d.ts",
|
|
47
|
+
"import": "./dist/agent.js",
|
|
48
|
+
"default": "./dist/agent.js"
|
|
49
|
+
},
|
|
50
|
+
"./bus": {
|
|
51
|
+
"types": "./dist/bus.d.ts",
|
|
52
|
+
"import": "./dist/bus.js",
|
|
53
|
+
"default": "./dist/bus.js"
|
|
54
|
+
},
|
|
37
55
|
"./client": {
|
|
38
56
|
"types": "./dist/client.d.ts",
|
|
39
57
|
"import": "./dist/client.js",
|
|
40
58
|
"default": "./dist/client.js"
|
|
41
59
|
},
|
|
60
|
+
"./durability": {
|
|
61
|
+
"types": "./dist/durability.d.ts",
|
|
62
|
+
"import": "./dist/durability.js",
|
|
63
|
+
"default": "./dist/durability.js"
|
|
64
|
+
},
|
|
65
|
+
"./internal/runtime/unavailable": {
|
|
66
|
+
"types": "./dist/internal/runtime/unavailable.d.ts",
|
|
67
|
+
"import": "./dist/internal/runtime/unavailable.js",
|
|
68
|
+
"default": "./dist/internal/runtime/unavailable.js"
|
|
69
|
+
},
|
|
42
70
|
"./server": {
|
|
43
71
|
"types": "./dist/server.d.ts",
|
|
44
72
|
"import": "./dist/server.js",
|
|
@@ -54,37 +82,48 @@
|
|
|
54
82
|
"import": "./dist/vue.js",
|
|
55
83
|
"default": "./dist/vue.js"
|
|
56
84
|
},
|
|
57
|
-
"./package.json": "./package.json"
|
|
85
|
+
"./package.json": "./package.json",
|
|
86
|
+
"./client/browser.js": {
|
|
87
|
+
"types": "./dist/client.d.ts",
|
|
88
|
+
"default": "./dist/client/browser.js"
|
|
89
|
+
}
|
|
58
90
|
},
|
|
59
91
|
"dependencies": {
|
|
60
|
-
"@tiptap/core": "^3.31.4",
|
|
61
92
|
"@tiptap/extension-collaboration": "^3.31.4",
|
|
62
|
-
"@tiptap/extension-document": "^3.31.4",
|
|
63
|
-
"@tiptap/extension-image": "^3.31.4",
|
|
64
|
-
"@tiptap/extension-table": "^3.31.4",
|
|
65
|
-
"@tiptap/markdown": "^3.31.4",
|
|
66
|
-
"@tiptap/pm": "^3.31.4",
|
|
67
|
-
"@tiptap/starter-kit": "^3.31.4",
|
|
68
93
|
"@tiptap/y-tiptap": "^3.0.9",
|
|
69
|
-
"@vite-hub/auth": "0.1
|
|
70
|
-
"@vite-hub/workspace": "0.1
|
|
71
|
-
"h3": "2.0.
|
|
94
|
+
"@vite-hub/auth": "0.3.1",
|
|
95
|
+
"@vite-hub/workspace": "0.3.1",
|
|
96
|
+
"h3": "^2.0.8",
|
|
97
|
+
"ioredis": "^5.11.1",
|
|
72
98
|
"lib0": "^0.2.119",
|
|
73
99
|
"marked": "17.0.6",
|
|
74
|
-
"nostics": "1.
|
|
100
|
+
"nostics": "1.4.0",
|
|
101
|
+
"postgres": "^3.4.9",
|
|
75
102
|
"prosemirror-model": "^1.25.12",
|
|
76
103
|
"prosemirror-state": "^1.4.4",
|
|
77
104
|
"prosemirror-transform": "^1.12.2",
|
|
78
105
|
"prosemirror-view": "^1.42.3",
|
|
79
106
|
"y-protocols": "^1.0.7",
|
|
80
107
|
"y-websocket": "^3.1.0",
|
|
81
|
-
"
|
|
82
|
-
"@vite-hub/runtime": "0.1.0"
|
|
108
|
+
"@vite-hub/runtime": "0.3.1"
|
|
83
109
|
},
|
|
84
110
|
"devDependencies": {
|
|
111
|
+
"@tiptap/core": "^3.31.4",
|
|
112
|
+
"@tiptap/extension-blockquote": "^3.31.4",
|
|
113
|
+
"@tiptap/extension-code": "^3.31.4",
|
|
114
|
+
"@tiptap/extension-document": "^3.31.4",
|
|
115
|
+
"@tiptap/extension-image": "^3.31.4",
|
|
116
|
+
"@tiptap/extension-table": "^3.31.4",
|
|
117
|
+
"@tiptap/markdown": "^3.31.4",
|
|
118
|
+
"@tiptap/pm": "^3.31.4",
|
|
119
|
+
"@tiptap/starter-kit": "^3.31.4",
|
|
85
120
|
"@types/json-schema": "^7.0.15",
|
|
86
121
|
"@types/node": "^24.19.1",
|
|
122
|
+
"@vite-hub/database": "0.3.1",
|
|
123
|
+
"@vite-hub/internal": "0.0.1",
|
|
124
|
+
"happy-dom": "21.0.3",
|
|
87
125
|
"linkedom": "^0.18.13",
|
|
126
|
+
"nitro": "^3.0.261103-rc",
|
|
88
127
|
"publint": "^0.3.25",
|
|
89
128
|
"typescript": "^6.0.3",
|
|
90
129
|
"vite": "^8.2.2",
|
|
@@ -92,12 +131,25 @@
|
|
|
92
131
|
"vitest": "^4.1.11",
|
|
93
132
|
"vue": "3.5.44",
|
|
94
133
|
"miniflare": "4.20260730.0",
|
|
95
|
-
"
|
|
134
|
+
"drizzle-orm": "1.0.0-rc.5",
|
|
135
|
+
"yjs": "^13.6.33"
|
|
96
136
|
},
|
|
97
137
|
"peerDependencies": {
|
|
138
|
+
"@tiptap/core": "^3.31.4",
|
|
139
|
+
"@tiptap/extension-blockquote": "^3.31.4",
|
|
140
|
+
"@tiptap/extension-code": "^3.31.4",
|
|
141
|
+
"@tiptap/extension-document": "^3.31.4",
|
|
142
|
+
"@tiptap/extension-image": "^3.31.4",
|
|
143
|
+
"@tiptap/extension-table": "^3.31.4",
|
|
144
|
+
"@tiptap/markdown": "^3.31.4",
|
|
145
|
+
"@tiptap/pm": "^3.31.4",
|
|
146
|
+
"@tiptap/starter-kit": "^3.31.4",
|
|
98
147
|
"@types/json-schema": "^7.0.15",
|
|
148
|
+
"nitro": "3.0.261102-rc || ^3.0.261103-rc",
|
|
99
149
|
"vite": ">=8.0.0",
|
|
100
|
-
"vue": "3.5.
|
|
150
|
+
"vue": "^3.5.0",
|
|
151
|
+
"drizzle-orm": "1.0.0-rc.5 || ^1.0.0",
|
|
152
|
+
"yjs": "^13.6.33"
|
|
101
153
|
},
|
|
102
154
|
"peerDependenciesMeta": {
|
|
103
155
|
"vite": {
|
|
@@ -108,12 +160,12 @@
|
|
|
108
160
|
}
|
|
109
161
|
},
|
|
110
162
|
"engines": {
|
|
111
|
-
"node": ">=
|
|
163
|
+
"node": ">=22.18.0"
|
|
112
164
|
},
|
|
113
165
|
"scripts": {
|
|
114
166
|
"build": "vp pack",
|
|
115
167
|
"dev": "vp pack --watch",
|
|
116
168
|
"typecheck": "vp run --cache -t @vite-hub/realtime#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
117
|
-
"test": "vp run -t @vite-hub/realtime#build && vp test"
|
|
169
|
+
"test": "vp run --cache -t @vite-hub/realtime#build && vp test"
|
|
118
170
|
}
|
|
119
171
|
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region src/application-path.ts
|
|
2
|
-
function resolveRealtimeApplicationPath(path, baseURL = typeof __VITEHUB_APP_BASE_URL__ === "undefined" ? "/" : __VITEHUB_APP_BASE_URL__) {
|
|
3
|
-
return baseURL === "/" ? path : `${baseURL.replace(/\/+$/, "")}${path}`;
|
|
4
|
-
}
|
|
5
|
-
//#endregion
|
|
6
|
-
export { resolveRealtimeApplicationPath as t };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { t as realtimeErrorDiagnostics } from "./error-diagnostics-Cvm6vRXQ.js";
|
|
2
|
-
import { Diagnostic } from "nostics";
|
|
3
|
-
//#region src/conflict.ts
|
|
4
|
-
const conflictCode = "REALTIME_DOCUMENT_CONFLICT";
|
|
5
|
-
/** Thrown by a document adapter when the stored digest no longer matches `ifDigest`. */
|
|
6
|
-
var RealtimeDocumentConflict = class RealtimeDocumentConflict extends Diagnostic {
|
|
7
|
-
constructor(why) {
|
|
8
|
-
const { code, docs, fix } = realtimeErrorDiagnostics.REALTIME_DOCUMENT_CONFLICT({ problem: why });
|
|
9
|
-
super({
|
|
10
|
-
code,
|
|
11
|
-
docs,
|
|
12
|
-
fix,
|
|
13
|
-
why: why ?? "The stored document changed since the realtime room loaded it."
|
|
14
|
-
}, RealtimeDocumentConflict);
|
|
15
|
-
this.name = "RealtimeDocumentConflict";
|
|
16
|
-
}
|
|
17
|
-
toJSON() {
|
|
18
|
-
return {
|
|
19
|
-
code: this.code,
|
|
20
|
-
data: void 0,
|
|
21
|
-
docs: this.docs,
|
|
22
|
-
fix: this.fix,
|
|
23
|
-
name: this.name,
|
|
24
|
-
why: this.why
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
function isRealtimeDocumentConflict(error) {
|
|
29
|
-
if (error instanceof RealtimeDocumentConflict) return true;
|
|
30
|
-
if (!error || typeof error !== "object" || !("code" in error)) return false;
|
|
31
|
-
return error.code === conflictCode;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
export { isRealtimeDocumentConflict as n, RealtimeDocumentConflict as t };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region src/durable-key.ts
|
|
2
|
-
/**
|
|
3
|
-
* The `Symbol.for` key of the global slot that holds the isolate's Durable Object for Realtime. The server reads it, and
|
|
4
|
-
* the generated Nitro plugin writes it without importing the server.
|
|
5
|
-
*/
|
|
6
|
-
const realtimeDurableObjectKey = "vitehub.realtime.durable-object";
|
|
7
|
-
//#endregion
|
|
8
|
-
export { realtimeDurableObjectKey as t };
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { defineErrors } from "@vite-hub/runtime";
|
|
2
|
-
//#region src/error-diagnostics.ts
|
|
3
|
-
const realtimeErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
4
|
-
docs: "https://vitehub.dev/docs/realtime/limits-and-errors",
|
|
5
|
-
codes: {
|
|
6
|
-
REALTIME_DISABLED: {
|
|
7
|
-
why: ({ action }) => `Realtime is disabled, so \`${action}()\` cannot run.`,
|
|
8
|
-
fix: "Set `enabled` to `true` on `useRealtimeTiptap()` before you call the method."
|
|
9
|
-
},
|
|
10
|
-
REALTIME_DISCONNECTED: {
|
|
11
|
-
why: ({ action }) => `The realtime document disconnected or changed during \`${action}()\`.`,
|
|
12
|
-
fix: "Call the method again after the new document connects. Read `synced` to know when it is ready."
|
|
13
|
-
},
|
|
14
|
-
REALTIME_INVALID_RESPONSE: {
|
|
15
|
-
why: ({ action }) => `The realtime server answered \`${action}()\` with a response that the client cannot use.`,
|
|
16
|
-
fix: "Use the same `@vite-hub/realtime` version on the client and the server, and build again."
|
|
17
|
-
},
|
|
18
|
-
REALTIME_MISSING_DOCUMENT: {
|
|
19
|
-
why: ({ action }) => `\`${action}()\` needs a document, and \`documentId\` is empty.`,
|
|
20
|
-
fix: "Pass a document path to `useRealtimeTiptap(definition, documentId)` before you call the method."
|
|
21
|
-
},
|
|
22
|
-
REALTIME_REQUEST_FAILED: {
|
|
23
|
-
why: ({ action, message, status }) => `The realtime \`${action}()\` request failed${status === void 0 ? "" : ` with HTTP ${status}`}${message ? `: ${message}` : "."}`,
|
|
24
|
-
fix: "Read `error.why` for the server message, and `error.cause` for a network error. Retry when the server is available again."
|
|
25
|
-
},
|
|
26
|
-
REALTIME_AWARENESS_OWNERSHIP_CONFLICT: {
|
|
27
|
-
why: "A realtime awareness client id belongs to another peer.",
|
|
28
|
-
fix: "Let each editor tab use its own Yjs awareness client. Do not reuse a client id on two connections."
|
|
29
|
-
},
|
|
30
|
-
REALTIME_AWARENESS_TOO_LARGE: {
|
|
31
|
-
why: "Realtime awareness state exceeds the 8 MiB room quota.",
|
|
32
|
-
fix: "Keep less data in awareness state. Store large values in the document or in Workspace."
|
|
33
|
-
},
|
|
34
|
-
REALTIME_DOCUMENT_TOO_LARGE: {
|
|
35
|
-
why: "The realtime document exceeds the 8 MiB room quota.",
|
|
36
|
-
fix: "Split the document into smaller documents, or keep large assets in Workspace or Blob."
|
|
37
|
-
},
|
|
38
|
-
REALTIME_INVALID_AWARENESS: {
|
|
39
|
-
why: "A realtime awareness update has a state that is not a plain object.",
|
|
40
|
-
fix: "Set awareness state to a plain object, for example `awareness.setLocalStateField('user', { name })`."
|
|
41
|
-
},
|
|
42
|
-
REALTIME_TOO_MANY_AWARENESS_CLIENTS: {
|
|
43
|
-
why: "One realtime peer sent more than 1,024 awareness clients.",
|
|
44
|
-
fix: "Use one awareness client for each editor tab."
|
|
45
|
-
},
|
|
46
|
-
REALTIME_DOCUMENT_CONFLICT: {
|
|
47
|
-
why: ({ problem }) => problem ?? "The stored document changed since the realtime room loaded it.",
|
|
48
|
-
fix: "Realtime re-seeds the room from the stored document. Listen to `onReset()` to recover text that the room did not save."
|
|
49
|
-
},
|
|
50
|
-
REALTIME_INVALID_PERSISTENCE: {
|
|
51
|
-
why: ({ name, reason }) => reason === "below-debounce" ? "Realtime `persistence.maxWait` must be at least `persistence.debounce`." : `Realtime \`persistence.${name}\` must be a non-negative number of milliseconds.`,
|
|
52
|
-
fix: "Set `persistence: { debounce: 2_000, maxWait: 10_000 }`, or remove the option to use these defaults."
|
|
53
|
-
},
|
|
54
|
-
REALTIME_INVALID_USER: {
|
|
55
|
-
why: "The realtime identity needs a user `id` that is a non-empty string of at most 256 characters.",
|
|
56
|
-
fix: "Return a user with an `id` from the Auth session or from `authorize()`."
|
|
57
|
-
},
|
|
58
|
-
REALTIME_MISSING_DIGEST: {
|
|
59
|
-
why: ({ operation }) => operation === "save" ? "Realtime saves need Workspace file digests, and the Workspace Store did not return one." : "Realtime checkpoints need a stored document, and the save returned no digest.",
|
|
60
|
-
fix: "Use a Workspace Store that returns file digests, or return `digest` from the document adapter `save()`."
|
|
61
|
-
},
|
|
62
|
-
REALTIME_AUTHORITY_CONFLICT: {
|
|
63
|
-
why: ({ authority, preset }) => authority === "memory" ? `Realtime authority "memory" is single-process only, and the ${preset} deployment preset runs more than one process.` : `Realtime authority "cloudflare" does not work with the ${preset} deployment preset.`,
|
|
64
|
-
fix: "Set `realtime.authority` to \"cloudflare\" with a Cloudflare preset, or to \"memory\" for one Node.js process."
|
|
65
|
-
},
|
|
66
|
-
REALTIME_MISSING_AUTHORITY: {
|
|
67
|
-
why: "Realtime production builds need one room authority, and ViteHub cannot select one for this deployment.",
|
|
68
|
-
fix: "Deploy with a Cloudflare preset to use Durable Objects, or set `realtime.authority` to \"memory\" for one Node.js process."
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
//#endregion
|
|
73
|
-
export { realtimeErrorDiagnostics as t };
|