( conn: ServerConnection.Any, scope: ServerScope, projects: ReturnType<typeof createServerProjects>, )
| 93 | }) |
| 94 | |
| 95 | function createServerCtx( |
| 96 | conn: ServerConnection.Any, |
| 97 | scope: ServerScope, |
| 98 | projects: ReturnType<typeof createServerProjects>, |
| 99 | ) { |
| 100 | const queryClient = new QueryClient({ |
| 101 | defaultOptions: { |
| 102 | queries: { |
| 103 | refetchOnReconnect: false, |
| 104 | refetchOnMount: false, |
| 105 | refetchOnWindowFocus: false, |
| 106 | }, |
| 107 | }, |
| 108 | }) |
| 109 | const sdk = createServerSdkContext(conn, scope) |
| 110 | const sync = createServerSyncContext(sdk) |
| 111 | |
| 112 | function enrich(project: { worktree: string; expanded: boolean }) { |
| 113 | const [childStore] = sync.child(project.worktree, { bootstrap: false }) |
| 114 | const projectID = childStore.project |
| 115 | const metadata = projectID |
| 116 | ? sync.data.project.find((x) => x.id === projectID) |
| 117 | : sync.data.project.find((x) => x.worktree === project.worktree) |
| 118 | |
| 119 | // Preserve local icon override from per-workspace localStorage cache (childStore.icon). |
| 120 | // Without this, different subdirectories of the same git repo would share the same |
| 121 | // icon from the database instead of using their individual overrides. |
| 122 | const base = { ...metadata, ...project } |
| 123 | if (childStore.icon) { |
| 124 | return { ...base, icon: { ...base.icon, override: childStore.icon } } |
| 125 | } |
| 126 | return base |
| 127 | } |
| 128 | |
| 129 | const projectsList = createMemo(() => projects.list().map(enrich)) |
| 130 | |
| 131 | const isLocal = |
| 132 | (conn?.type === "sidecar" && conn.variant === "base") || (conn?.type === "http" && isLocalHost(conn.http.url)) |
| 133 | |
| 134 | return { |
| 135 | queryClient, |
| 136 | sdk, |
| 137 | sync, |
| 138 | isLocal, |
| 139 | projects: { |
| 140 | ...projects, |
| 141 | list: projectsList, |
| 142 | }, |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | export type ServerCtx = ReturnType<typeof createServerCtx> |
| 147 |
no test coverage detected