cosveti-sync 0.0.7 → 0.0.8
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/dist/tiptap/index.js +47 -44
- package/package.json +1 -1
package/dist/tiptap/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getCachedState } from './getCachedState.js';
|
|
2
2
|
import { derived, writable } from 'svelte/store';
|
|
3
3
|
import { syncExtension } from './syncExtension.js';
|
|
4
|
+
import { BROWSER } from 'esm-env';
|
|
4
5
|
// import { useConvexClient } from 'convex-svelte';
|
|
5
6
|
export const MAX_STEPS_SYNC = 10;
|
|
6
7
|
export const SNAPSHOT_DEBOUNCE_MS = 1000;
|
|
@@ -82,53 +83,55 @@ export function createInitialStateStore(convex, syncApi, id, cacheKeyPrefix) {
|
|
|
82
83
|
// So the store will be set first, then a newer version from server will arrive
|
|
83
84
|
// const queryArgs = cachedState ? 'skip' : { id };
|
|
84
85
|
const queryArgs = { id };
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
86
|
+
if (BROWSER) {
|
|
87
|
+
convex
|
|
88
|
+
.query(syncApi.getSnapshot, queryArgs)
|
|
89
|
+
.then((result) => {
|
|
90
|
+
// Handle missing document case
|
|
91
|
+
if (!result) {
|
|
92
|
+
store.set({ loading: false, initialContent: null });
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const { content, version } = result;
|
|
96
|
+
// Handle explicit null content
|
|
97
|
+
if (content === null) {
|
|
98
|
+
store.set({ loading: false, initialContent: null });
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// Validate content type before parsing
|
|
102
|
+
if (typeof content !== 'string') {
|
|
103
|
+
const errorMsg = `Invalid content type received: ${typeof content}`;
|
|
104
|
+
console.error(errorMsg, { content, version });
|
|
105
|
+
throw new Error(errorMsg); // Propagate to catch block for unified error handling
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
// Safely parse and validate structure
|
|
109
|
+
const parsedContent = JSON.parse(content);
|
|
110
|
+
// Optional: Add runtime type validation here if Content has specific structure
|
|
111
|
+
// if (!isValidContent(parsedContent)) throw new Error('Invalid content structure');
|
|
112
|
+
store.set({
|
|
113
|
+
loading: false,
|
|
114
|
+
initialContent: parsedContent, // Assert only after validation
|
|
115
|
+
initialVersion: version
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (parseError) {
|
|
119
|
+
console.error('Content parsing failed:', parseError, { rawContent: content });
|
|
120
|
+
throw new Error(`JSON parse error: ${parseError instanceof Error ? parseError.message : 'Unknown error'}`);
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.catch((error) => {
|
|
124
|
+
console.error('Snapshot load failed:', error);
|
|
125
|
+
// Unified error state update (covers query errors, type errors, parse errors)
|
|
110
126
|
store.set({
|
|
111
127
|
loading: false,
|
|
112
|
-
initialContent:
|
|
113
|
-
|
|
128
|
+
initialContent: null
|
|
129
|
+
// Optional: Add error tracking if your store supports it
|
|
130
|
+
// error: error instanceof Error ? error.message : 'Unknown snapshot error'
|
|
114
131
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
console.error('Content parsing failed:', parseError, { rawContent: content });
|
|
118
|
-
throw new Error(`JSON parse error: ${parseError instanceof Error ? parseError.message : 'Unknown error'}`);
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
.catch((error) => {
|
|
122
|
-
console.error('Snapshot load failed:', error);
|
|
123
|
-
// Unified error state update (covers query errors, type errors, parse errors)
|
|
124
|
-
store.set({
|
|
125
|
-
loading: false,
|
|
126
|
-
initialContent: null
|
|
127
|
-
// Optional: Add error tracking if your store supports it
|
|
128
|
-
// error: error instanceof Error ? error.message : 'Unknown snapshot error'
|
|
132
|
+
// Re-throw if caller needs to handle errors (remove if errors should be fully absorbed)
|
|
133
|
+
// throw error;
|
|
129
134
|
});
|
|
130
|
-
|
|
131
|
-
// throw error;
|
|
132
|
-
});
|
|
135
|
+
}
|
|
133
136
|
return store;
|
|
134
137
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "cosveti-sync",
|
|
3
3
|
"description": "A convex component for syncing tiptap in a svelte project",
|
|
4
4
|
"homepage": "https://github.com/feavel1/cosveti-sync",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.8",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite dev",
|
|
8
8
|
"build": "vite build && npm run prepack",
|