Skip to content

Commit c767a55

Browse files
committed
refactor(epicenter): enhance type safety by excluding internal properties in iterActions and adding type imports in createServer
1 parent 474f997 commit c767a55

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/epicenter/src/core/epicenter/client.shared.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ export function* iterActions<TWorkspaces extends readonly AnyWorkspaceConfig[]>(
9595
for (const [workspaceId, workspaceClient] of Object.entries(
9696
workspaceClients,
9797
)) {
98-
// Extract all exports (excluding cleanup methods from the workspace interface)
98+
// Extract all exports (excluding cleanup methods and internal properties from the workspace interface)
9999
const {
100100
destroy: _workspaceDestroy,
101101
[Symbol.asyncDispose]: _workspaceAsyncDispose,
102+
$ydoc: _$ydoc,
102103
...workspaceExports
103104
} = workspaceClient as WorkspaceClient<WorkspaceExports>;
104105

packages/epicenter/src/server/server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { openapi } from '@elysiajs/openapi';
22
import { Elysia } from 'elysia';
33
// import { mcp } from 'elysia-mcp';
44
import { Err, isResult, Ok } from 'wellcrafted/result';
5+
import type { WorkspaceExports } from '../core/actions';
56
import {
67
createEpicenterClient,
78
type EpicenterConfig,
89
iterActions,
910
} from '../core/epicenter';
1011
import type {
1112
AnyWorkspaceConfig,
13+
WorkspaceClient,
1214
WorkspacesToClients,
1315
} from '../core/workspace';
1416
import { createSyncPlugin } from './sync';
@@ -105,8 +107,11 @@ export async function createServer<
105107
createSyncPlugin({
106108
getDoc: (room) => {
107109
// Room name is the workspace ID
108-
const workspace =
109-
client[room as keyof WorkspacesToClients<TWorkspaces>];
110+
// Type assertion needed because TypeScript can't prove the generic
111+
// WorkspacesToClients mapping resolves to WorkspaceClient
112+
const workspace = client[
113+
room as keyof WorkspacesToClients<TWorkspaces>
114+
] as WorkspaceClient<WorkspaceExports> | undefined;
110115
return workspace?.$ydoc;
111116
},
112117
}),

0 commit comments

Comments
 (0)