Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

compatibility.ts

30 lines1.2 KB

1import {
2 ORCHESTRATION_PROTOCOL_QUERY_PARAM,
3 ORCHESTRATION_PROTOCOL_VERSION,
4 type ExecutionEnvironmentDescriptor,
5} from "@t3tools/contracts";
6​
7import { ConnectionBlockedError } from "./model.ts";
8​
9export function orchestrationProtocolCompatibilityError(
10 descriptor: ExecutionEnvironmentDescriptor,
11): ConnectionBlockedError | null {
12 // Servers shipped before negotiation use the original wire protocol.
13 const serverProtocolVersion = descriptor.orchestrationProtocolVersion ?? 1;
14 if (serverProtocolVersion === ORCHESTRATION_PROTOCOL_VERSION) {
15 return null;
16 }
17 return new ConnectionBlockedError({
18 reason: "unsupported",
19 detail:
20 serverProtocolVersion > ORCHESTRATION_PROTOCOL_VERSION
21 ? `This client is not supported by this server. Update your app or use a compatible release to connect to ${descriptor.label}.`
22 : `This client requires a newer server. Update T3 Code on ${descriptor.label} to connect.`,
23 });
25​
26export function appendOrchestrationProtocol(socketUrl: string): string {
27 const url = new URL(socketUrl);
28 url.searchParams.set(ORCHESTRATION_PROTOCOL_QUERY_PARAM, String(ORCHESTRATION_PROTOCOL_VERSION));
29 return url.toString();