Skip to content

Commit 90edab7

Browse files
committed
refactor(persistence): update setupPersistence to use generic WorkspaceSchema in desktop and web providers
1 parent f44a87d commit 90edab7

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/epicenter/src/providers/persistence/desktop.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { mkdirSync } from 'node:fs';
22
import { join } from 'node:path';
33
import * as Y from 'yjs';
4+
import type { Provider, ProviderContext } from '../../core/provider.node';
45
import { defineProviderExports } from '../../core/provider.shared';
5-
import type { Provider } from '../../core/provider.node';
6+
import type { WorkspaceSchema } from '../../core/schema';
67

78
/** Debounce delay for filesystem writes (ms) */
89
const DEBOUNCE_MS = 100;
@@ -64,7 +65,11 @@ const DEBOUNCE_MS = 100;
6465
* });
6566
* ```
6667
*/
67-
export const setupPersistence = (async ({ id, ydoc, epicenterDir }) => {
68+
export const setupPersistence = (async <TSchema extends WorkspaceSchema>({
69+
id,
70+
ydoc,
71+
epicenterDir,
72+
}: ProviderContext<TSchema>) => {
6873
if (!epicenterDir) {
6974
throw new Error(
7075
'Persistence provider requires Bun environment with filesystem access',

packages/epicenter/src/providers/persistence/web.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IndexeddbPersistence } from 'y-indexeddb';
2-
import type { Provider } from '../../core/provider.browser';
2+
import type { Provider, ProviderContext } from '../../core/provider.browser';
3+
import type { WorkspaceSchema } from '../../core/schema';
34

45
/**
56
* YJS document persistence provider using IndexedDB.
@@ -88,7 +89,9 @@ import type { Provider } from '../../core/provider.browser';
8889
*
8990
* @see {@link setupPersistence} from `@epicenter/hq/persistence/desktop` for Node.js/filesystem version
9091
*/
91-
export const setupPersistence = (({ ydoc }) => {
92+
export const setupPersistence = (<TSchema extends WorkspaceSchema>({
93+
ydoc,
94+
}: ProviderContext<TSchema>) => {
9295
// y-indexeddb handles both loading and saving automatically
9396
// Uses the YDoc's guid as the IndexedDB database name
9497
const persistence = new IndexeddbPersistence(ydoc.guid, ydoc);

0 commit comments

Comments
 (0)