cosveti-sync 0.0.6 → 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/README.md CHANGED
@@ -48,7 +48,7 @@ First, set up the backend API in your Convex project. Create a file like `convex
48
48
  ```typescript
49
49
  import { defineApp } from 'convex/server';
50
50
 
51
- import tiptapSync from '../lib/component/convex.config.js';
51
+ import tiptapSync from 'cosveti-sync/convex.config.js';
52
52
 
53
53
  const app = defineApp();
54
54
 
@@ -61,7 +61,7 @@ export default app;
61
61
  First, set up the backend API in your Convex project. Create a file like `convex/tiptapSync.ts`:
62
62
 
63
63
  ```typescript
64
- import { TiptapSyncClient } from '../lib/client/index.js';
64
+ import { TiptapSyncClient } from 'cosveti-sync';
65
65
  import { components } from './_generated/api.js';
66
66
 
67
67
  const tiptapSync = new TiptapSyncClient(components.tiptapSync);
@@ -122,7 +122,7 @@ Here's a complete example showing how to integrate the library:
122
122
 
123
123
  ```svelte
124
124
  <script lang="ts">
125
- import { useTiptapSync } from '$lib/index.js';
125
+ import { useTiptapSync } from 'cosveti-sync/tiptap';
126
126
  import { api } from '$convex/_generated/api.js';
127
127
  import type { ConvexClient } from 'convex/browser';
128
128
  import { useConvexClient } from 'convex-svelte';
@@ -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
- convex
86
- .query(syncApi.getSnapshot, queryArgs)
87
- .then((result) => {
88
- // Handle missing document case
89
- if (!result) {
90
- store.set({ loading: false, initialContent: null });
91
- return;
92
- }
93
- const { content, version } = result;
94
- // Handle explicit null content
95
- if (content === null) {
96
- store.set({ loading: false, initialContent: null });
97
- return;
98
- }
99
- // Validate content type before parsing
100
- if (typeof content !== 'string') {
101
- const errorMsg = `Invalid content type received: ${typeof content}`;
102
- console.error(errorMsg, { content, version });
103
- throw new Error(errorMsg); // Propagate to catch block for unified error handling
104
- }
105
- try {
106
- // Safely parse and validate structure
107
- const parsedContent = JSON.parse(content);
108
- // Optional: Add runtime type validation here if Content has specific structure
109
- // if (!isValidContent(parsedContent)) throw new Error('Invalid content structure');
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: parsedContent, // Assert only after validation
113
- initialVersion: version
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
- catch (parseError) {
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
- // Re-throw if caller needs to handle errors (remove if errors should be fully absorbed)
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.6",
5
+ "version": "0.0.8",
6
6
  "scripts": {
7
7
  "dev": "vite dev",
8
8
  "build": "vite build && npm run prepack",