Skip to content

Commit 4730c6f

Browse files
committed
Fix null vs undefined environment scoping and remove unused exports
- Replace `??` with explicit undefined check in runSnapshotRecovery so that an explicit null environmentId is preserved rather than falling through to the active environment. - Remove unused exported functions (scopeThreadSessionRef, resolveEnvironmentClient, tagEnvironmentValue, attachEnvironmentDescriptor) and their supporting types from client-runtime.
1 parent 95af050 commit 4730c6f

File tree

3 files changed

+7
-52
lines changed

3 files changed

+7
-52
lines changed

apps/web/src/routes/__root.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,10 @@ function EventRouter() {
531531
try {
532532
const snapshot = await api.orchestration.getSnapshot();
533533
if (!disposed) {
534-
syncServerReadModel(snapshot, environmentId ?? resolveCurrentEnvironmentId());
534+
syncServerReadModel(
535+
snapshot,
536+
environmentId !== undefined ? environmentId : resolveCurrentEnvironmentId(),
537+
);
535538
reconcileSnapshotDerivedState();
536539
if (recovery.completeSnapshotRecovery(snapshot.snapshotSequence)) {
537540
void runReplayRecovery("sequence-gap");

packages/client-runtime/src/knownEnvironment.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EnvironmentId, ExecutionEnvironmentDescriptor } from "@t3tools/contracts";
1+
import type { EnvironmentId } from "@t3tools/contracts";
22

33
export interface KnownEnvironmentConnectionTarget {
44
readonly type: "ws";
@@ -37,14 +37,3 @@ export function getKnownEnvironmentBaseUrl(
3737
): string | null {
3838
return environment?.target.wsUrl ?? null;
3939
}
40-
41-
export function attachEnvironmentDescriptor(
42-
environment: KnownEnvironment,
43-
descriptor: ExecutionEnvironmentDescriptor,
44-
): KnownEnvironment {
45-
return {
46-
...environment,
47-
environmentId: descriptor.environmentId,
48-
label: descriptor.label,
49-
};
50-
}

packages/client-runtime/src/scoped.ts

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,10 @@ import type {
22
EnvironmentId,
33
ProjectId,
44
ScopedProjectRef,
5-
ScopedThreadSessionRef,
65
ScopedThreadRef,
76
ThreadId,
87
} from "@t3tools/contracts";
98

10-
interface EnvironmentScopedRef<TId extends string> {
11-
readonly environmentId: EnvironmentId;
12-
readonly id: TId;
13-
}
14-
15-
export interface EnvironmentClientRegistry<TClient> {
16-
readonly getClient: (environmentId: EnvironmentId) => TClient | null | undefined;
17-
}
18-
199
export function scopeProjectRef(
2010
environmentId: EnvironmentId,
2111
projectId: ProjectId,
@@ -27,34 +17,7 @@ export function scopeThreadRef(environmentId: EnvironmentId, threadId: ThreadId)
2717
return { environmentId, threadId };
2818
}
2919

30-
export function scopeThreadSessionRef(
31-
environmentId: EnvironmentId,
32-
threadId: ThreadId,
33-
): ScopedThreadSessionRef {
34-
return { environmentId, threadId };
35-
}
36-
37-
export function scopedRefKey(
38-
ref: EnvironmentScopedRef<string> | ScopedProjectRef | ScopedThreadRef | ScopedThreadSessionRef,
39-
): string {
40-
const localId = "id" in ref ? ref.id : "projectId" in ref ? ref.projectId : ref.threadId;
20+
export function scopedRefKey(ref: ScopedProjectRef | ScopedThreadRef): string {
21+
const localId = "projectId" in ref ? ref.projectId : ref.threadId;
4122
return `${ref.environmentId}:${localId}`;
4223
}
43-
44-
export function resolveEnvironmentClient<TClient>(
45-
registry: EnvironmentClientRegistry<TClient>,
46-
ref: EnvironmentScopedRef<string>,
47-
): TClient {
48-
const client = registry.getClient(ref.environmentId);
49-
if (!client) {
50-
throw new Error(`No client registered for environment ${ref.environmentId}.`);
51-
}
52-
return client;
53-
}
54-
55-
export function tagEnvironmentValue<T>(
56-
environmentId: EnvironmentId,
57-
value: T,
58-
): { readonly environmentId: EnvironmentId; readonly value: T } {
59-
return { environmentId, value };
60-
}

0 commit comments

Comments
 (0)